1. 下载压缩包,解压得到Reverse.class,用IDEA打开,得到以下源码
1 import java.util.ArrayList; 2 import java.util.Scanner; 3 4 public class Reverse { 5 public Reverse() { 6 } 7 8 public static void main(String[] args) { 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 ArrayList<Integer> Resultlist = new ArrayList(); 20 21 for(int i = 0; i < arr.length; ++i) { 22 int result = arr[i] + 64 ^ 32; 23 Resultlist.add(result); 24 } 25 26 int[] KEY = new int[]{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 29 for(int j = 0; j < KEY.length; ++j) { 30 KEYList.add(KEY[j]); 31 } 32 33 System.out.println("Result:"); 34 if (Resultlist.equals(KEYList)) { 35 System.out.println("Congratulations!"); 36 } else { 37 System.err.println("Error!"); 38 } 39 40 } 41 }
2. 大致的意思是:输入的字符串flag会被转成字符串列表,然后对每个元素进行加密。加密的方法是:每个元素加上64后再与32异或。加密完转换成整型需与KEY各元素相等。所以对KEY中各元素异或32后减去64再转char即可得到flag。
3. 解密代码如下:
1 public class JavaReverseDecypto { 2 public static void main(String[] args) { 3 int[] KEY = new int[]{180, 136, 137, 147, 191, 137, 147, 191, 148, 136, 133, 191, 134, 140, 129, 135, 191, 65}; 4 int len = KEY.length; 5 6 char[] flag = new char[len]; 7 for (int i = 0; i < len; ++i) { 8 flag[i] = (char) ((KEY[i] ^ 32) - 64); 9 System.out.print(flag[i]); 10 } 11 } 12 }
4. 输出结果为This_is_the_flag_!