⚠⚠⚠一点都不EASY⚠⚠⚠

本人水平有限,Enigma加解密比较复杂,暂得出的结论是双转子的Enigma算法
免责声明:在互联网查询后没有找到比较官方的正确答案,此结论不一定正确⚠

题目

CSDN免积分下载

查壳

先查壳(PKiD等),有壳脱壳,没壳用AndroidKiller等反编译工具打开查看JAVA代码
无壳APK

Java Decompiler - MainActivity-onCreate

image.png

答案

flag{venividivkcr}

Writeup

解题

运行

image.png

解题思路

搜索字符串

使用反编译工具的字符串搜索功能,搜索运行后失败的提示字符串“You are wrong”:
image.png
在Java Decompiler中,找到该文件查看代码:
image.png

MainActivity

搜不出来或者没有思路时,应该先看Android程序的入口——也就是MainActivity函数。

代码逻辑

MainActivity

主要代码为+if判断:

  1. protected void onCreate(Bundle paramBundle)
  2. {
  3. /*——————————省略——————————*/
  4. if (MainActivity.a(((EditText)((MainActivity)jdField_this).findViewById(2131427445)).getText().toString()).booleanValue())
  5. {
  6. Toast.makeText(jdField_this, "You are right!", 1).show();
  7. }
  8. for (;;)
  9. {
  10. return;
  11. Toast.makeText(jdField_this, "You are wrong! Bye~", 1).show();
  12. /*——————————省略——————————*/
  13. }

a函数

将字符串传给a类的a方法后返回的值作为b类的方法a的参数——简化为(方法a(方法b(字符串)))

  1. private static char a(String paramString, b paramb, a parama)
  2. {
  3. return parama.a(paramb.a(paramString));
  4. }

b类的方法a

  1. public Integer a(String paramString)
  2. {
  3. int i = 0;
  4. Object localObject = Integer.valueOf(0);
  5. if (b.contains(paramString.toLowerCase()))
  6. {
  7. int j = b.indexOf(paramString);
  8. paramString = (String)localObject;
  9. for (;;)
  10. {
  11. localObject = paramString;
  12. if (i >= a.size() - 1)
  13. {
  14. break;
  15. }
  16. if (a.get(i) == Integer.valueOf(j))
  17. {
  18. paramString = Integer.valueOf(i);
  19. }
  20. i++;
  21. }
  22. }
  23. if (paramString.contains(" ")) {}
  24. for (localObject = Integer.valueOf(-10);; localObject = Integer.valueOf(-1))
  25. {
  26. a();
  27. return (Integer)localObject;
  28. }
  29. }

a类的方法a

  1. public char a(Integer paramInteger)
  2. {
  3. int i = 0;
  4. Integer localInteger = Integer.valueOf(0);
  5. if (paramInteger.intValue() == -10)
  6. {
  7. a();
  8. i = " ".charAt(0);
  9. }
  10. for (int j = i;; j = i)
  11. {
  12. return j;
  13. while (i < a.size() - 1)
  14. {
  15. if (a.get(i) == paramInteger)
  16. {
  17. localInteger = Integer.valueOf(i);
  18. }
  19. i++;
  20. }
  21. a();
  22. i = b.charAt(localInteger.intValue());
  23. }
  24. }

结论

代码跳来跳去看,介绍的意义不大,内容应该更偏向于说明代码对应的算法和逻辑。
但是由于比较复杂,本人表达能力优先,自己也没理解的特别清楚,也担心表达错误误导他人,建议自行搜索Enigma加密器。
暂认为是Enigma加解密,但是从三转子改成了双转子(存疑)

Enigma加解密

Enigma(恩尼格玛)加密解密

特征

比较核心和特征性的代码:

  1. package com.a.easyjava;
  2. import java.util.ArrayList;
  3. public class a
  4. {
  5. public static ArrayList<Integer> a = new ArrayList();
  6. static String b = "abcdefghijklmnopqrstuvwxyz";
  7. static Integer d = Integer.valueOf(0);
  8. Integer[] c = { Integer.valueOf(7), Integer.valueOf(14), Integer.valueOf(16), Integer.valueOf(21), Integer.valueOf(4), Integer.valueOf(24), Integer.valueOf(25), Integer.valueOf(20), Integer.valueOf(5), Integer.valueOf(15), Integer.valueOf(9), Integer.valueOf(17), Integer.valueOf(6), Integer.valueOf(13), Integer.valueOf(3), Integer.valueOf(18), Integer.valueOf(12), Integer.valueOf(10), Integer.valueOf(19), Integer.valueOf(0), Integer.valueOf(22), Integer.valueOf(2), Integer.valueOf(11), Integer.valueOf(23), Integer.valueOf(1), Integer.valueOf(8) };
  9. public a(Integer paramInteger)
  10. {
  11. for (int i = paramInteger.intValue(); i < this.c.length; i++)
  12. {
  13. a.add(this.c[i]);
  14. }
  15. for (i = 0; i < paramInteger.intValue(); i++)
  16. {
  17. a.add(this.c[i]);
  18. }
  19. }
  20. public static void a()
  21. {
  22. Integer localInteger = d;
  23. d = Integer.valueOf(d.intValue() + 1);
  24. if (d.intValue() == 25)
  25. {
  26. int i = ((Integer)a.get(0)).intValue();
  27. a.remove(0);
  28. a.add(Integer.valueOf(i));
  29. d = Integer.valueOf(0);
  30. }
  31. }
  32. public char a(Integer paramInteger)
  33. {
  34. int i = 0;
  35. Integer localInteger = Integer.valueOf(0);
  36. if (paramInteger.intValue() == -10)
  37. {
  38. a();
  39. i = " ".charAt(0);
  40. }
  41. for (int j = i;; j = i)
  42. {
  43. return j;
  44. while (i < a.size() - 1)
  45. {
  46. if (a.get(i) == paramInteger)
  47. {
  48. localInteger = Integer.valueOf(i);
  49. }
  50. i++;
  51. }
  52. a();
  53. i = b.charAt(localInteger.intValue());
  54. }
  55. }
  56. }
特征 对应代码
字母表 static String b = “abcdefghijklmnopqrstuvwxyz”;
转子
取值为0-25的数组
Integer[] c = { Integer.valueOf(7), Integer.valueOf(14), Integer.valueOf(16), Integer.valueOf(21), Integer.valueOf(4), Integer.valueOf(24), Integer.valueOf(25), Integer.valueOf(20), Integer.valueOf(5), Integer.valueOf(15), Integer.valueOf(9), Integer.valueOf(17), Integer.valueOf(6), Integer.valueOf(13), Integer.valueOf(3), Integer.valueOf(18), Integer.valueOf(12), Integer.valueOf(10), Integer.valueOf(19), Integer.valueOf(0), Integer.valueOf(22), Integer.valueOf(2), Integer.valueOf(11), Integer.valueOf(23), Integer.valueOf(1), Integer.valueOf(8) };
数字25 if (d.intValue() == 25)

🐍Python脚本🐍

Python实现Enigma算法

  1. #转子的类型是双端队列
  2. from collections import deque
  3. #字母表
  4. tableAlphabet = deque("abcdefghijklmnopqrstuvwxyz")
  5. #转子1
  6. EnigmaRotor1 = deque([8, 25, 17, 23, 7, 22, 1, 16, 6, 9, 21, 0, 15, 5, 10, 18, 2, 24, 4, 11, 3, 14, 19, 12, 20, 13])
  7. #转子2
  8. EnigmaRotor2 = deque([7, 14, 16, 21, 4, 24, 25, 20, 5, 15, 9, 17, 6, 13, 3, 18, 12, 10, 19, 0, 22, 2, 11, 23, 1, 8])
  9. textCipher = 'wigwrkaugala'
  10. flag = ""
  11. #转动
  12. #左移2位
  13. for _ in range(2):
  14. EnigmaRotor1.append(EnigmaRotor1.popleft())
  15. #左移3位
  16. for _ in range(3):
  17. EnigmaRotor2.append(EnigmaRotor2.popleft())
  18. #Enigma加密
  19. def decipherEnigma(textCipher):
  20. global flag
  21. #得到在字母表中的索引值
  22. i = EnigmaRotor2[(ord(textCipher) - ord('a'))]
  23. i = EnigmaRotor1[(i)]
  24. flag += tableAlphabet[i]
  25. EnigmaRotor1.append(EnigmaRotor1.popleft())
  26. tableAlphabet.append(tableAlphabet.popleft())
  27. for s in textCipher:
  28. decipherEnigma(s)
  29. print("flag{" + flag + "}")

image.png

py-enigma

使用文档
参考手册

from enigma.machine import EnigmaMachine

研究中

在线

研究中
image.png