下载得到pyc文件,尝试反编译,未能完全成功,问题出在flag3
str = 'jYygTOy' + 'cmNycWNyYmM1Ujf'
import base64
def flag1():
code = str[::-3]
result = ''
for i in code:
ss = ord(i) - 1
result += chr(ss)
print result[::-1]
def flag2():
code = str[::-2]
result = ''
for i in code:
ss = ord(i) - 1
result += chr(ss)
print result[::-2]
def flag3():
pass
# WARNING: Decompyle incomplete
flag1()
尝试用uncompyle6
比对上面的代码,推测第一段显示的字符串均为有效字符串,提取出来,发现是个逆序的base64编码结果
=cWbihGfyMzNllzZ0cjZzMWN5cTM4YjYygTOycmNycWNyYmM1Ujf
上java,翻转一下
/**
* 翻转字符串
*
* @param str
* @return
*/
static String rev(String str) {
String str_r = (new StringBuilder(str)).reverse().toString();
return str_r;
}
结果:
fjU1MmYyNWcyNmcyOTgyYjY4MTc5NWMzZjc0ZzllNzMyfGhibWc=
base64解密
/**
* base64解密
*
* @param str
* @return
*/
static String bas64(String str) {
Base64.Decoder de = Base64.getDecoder();
String str_bas = new String((de.decode(str)));
return str_bas;
}
结果:
~552f25g26g2982b681795c3f74g9e732|hbmg
又是一个逆序,再次翻转
结果:
gmbh|237e9g47f3c597186b2892g62g52f255~
怀疑凯撒加密,尝试解密(借鉴自:51cto)
/**
* 凯撒加/解密
*
* @param str
* @return
*/
static String caesar(int key, String str) {
StringBuilder es = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c > 'a' && c < 'z') {
c += key % 26;
if (c < 'a'){
c += 26;
}else if (c > 'z'){
c -= 26;
}
} else if (c > 'A' && c < 'Z') {
c += key % 26;
if (c < 'A'){
c += 26;
}else if (c > 'Z'){
c -= 26;
}
}
es.append(c);
}
String str_ca = es.toString();
return str_ca;
}
结果:
是凯撒,又不完全是,flag也就是把字符串中所有字符的ASCII向前提了一位,那就从第五位开始移位
/**
* 最终结果(由题,flag前四位为“flag”)
*
* @param str
* @return
*/
static void final_res(String str){
System.out.print("flag");
for (int i = 4; i < str.length(); i++) {
char res = (char)(str.charAt(i) - 1);
System.out.print(res);
}
System.out.println();
}
最终结果:
flag{126e8g36f2c486075b1781g51g41f144}
完整代码:
import java.util.Base64;
/**
* @Author: Jack Jparrow
* @Date: 2021-11-21 21:03:03
* @LastEditTime: 2021-11-21 21:51:43
* @LastEditors: Jack Jparrow
* @Description: 翻转字符串,base64解密,凯撒解密
*/
public class testpyc {
public static void main(String[] args) {
for (int i = 26; i > 0; i--) {// 加密正着,解密反过来
String result = rev(caesar(i, bas64(rev("=cWbihGfyMzNllzZ0cjZzMWN5cTM4YjYygTOycmNycWNyYmM1Ujf"))));
// System.out.println(result + " " + (26 - i));
if (i == 1) {
final_res(result);
}
}
}
/**
* 翻转字符串
*
* @param str
* @return
*/
static String rev(String str) {
String str_r = (new StringBuilder(str)).reverse().toString();
return str_r;
}
/**
* base64解密
*
* @param str
* @return
*/
static String bas64(String str) {
Base64.Decoder de = Base64.getDecoder();
String str_bas = new String((de.decode(str)));
return str_bas;
}
/**
* 凯撒加/解密
*
* @param str
* @return
*/
static String caesar(int key, String str) {
StringBuilder es = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c > 'a' && c < 'z') {
c += key % 26;
if (c < 'a'){
c += 26;
}else if (c > 'z'){
c -= 26;
}
} else if (c > 'A' && c < 'Z') {
c += key % 26;
if (c < 'A'){
c += 26;
}else if (c > 'Z'){
c -= 26;
}
}
es.append(c);
}
String str_ca = es.toString();
return str_ca;
}
/**
* 最终结果(由题,flag前四位为“flag”)
*
* @param str
* @return
*/
static void final_res(String str){
System.out.print("flag");
for (int i = 4; i < str.length(); i++) {
char res = (char)(str.charAt(i) - 1);// 向前提一位
System.out.print(res);
}
System.out.println();
}
}