BUUCTF-RE-JAVA逆向解密
一、
.class文件用jd-gui打开
二、分析
1 import java.io.PrintStream; 2 import java.util.ArrayList; 3 import java.util.Scanner; 4 5 public class Reverse 6 { 7 public static void main(String[] args) 8 { 9 Scanner s = new Scanner(System.in); 10 System.out.println("Please input the flag :"); 11 String str = s.next(); 12 System.out.println("Your input is :"); 13 System.out.println(str); 14 char[] stringArr = str.toCharArray(); 15 Encrypt(stringArr); 16 } 17 18 public static void Encrypt(char[] arr) 19 { 20 ArrayList<Integer> Resultlist = new ArrayList(); 21 for (int i = 0; i < arr.length; i++) 22 { 23 int result = arr[i] + '@' ^ 0x20; 24 Resultlist.add(Integer.valueOf(result)); 25 } 26 int[] KEY = { 180, 136, 137, 147, 191, 137, 147, 191, 148, 136, 133, 191, 134, 140, 129, 135, 191, 65 }; 27 ArrayList<Integer> KEYList = new ArrayList(); 28 for (int j = 0; j < KEY.length; j++) { 29 KEYList.add(Integer.valueOf(KEY[j])); 30 } 31 System.out.println("Result:"); 32 if (Resultlist.equals(KEYList)) { 33 System.out.println("Congratulations!"); 34 } else { 35 System.err.println("Error!"); 36 } 37 } 38 }
第23行flag做了 arr[i]+'@' ^ 0x20;
第26行可以看到 int[] KEY = { 180, 136, 137, 147, 191, 137, 147, 191, 148, 136, 133, 191, 134, 140, 129, 135, 191, 65 };
key = [180, 136, 137, 147, 191, 137, 147, 191, 148, 136, 133, 191, 134, 140, 129, 135, 191, 65] flag = '' for i in key: flag+=chr(i-ord('@')^0x20) print(flag)
* chr是将ascii码转字符 ord是将字符转ascii码
三、flag
flag{This_is_the_flag_!}