Drennthew

Solution to Cracker 3 for ZZAZZ April Fools 2018

Apr 10th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. // C++ program to brute-force the key for the 3rd cracker challenge in ZZAZZ's April Fool's 2018.
  2. //
  3. // The "xorvals" (derived key) were determined manually; I observed that after the key was
  4. // hashed up, each byte had no effect on the others, meaning that I could try all 256
  5. // values for a particular byte and choose the one that looked most promising. The result,
  6. // was that I built up the image one set of lines at a time. Even when I had nothing to go on,
  7. // it was easy to pick the correct bytes due to how much blank space they produced (compared
  8. // to random noise).
  9. //
  10. // This part was accomplished by hacking the code, because I'm better at writing gb-z80
  11. // than c++. :)
  12. //
  13. // I wrote assembly to cycle through all 256 values quickly. Try this savestate to see it
  14. // in action (custom code at 02:b89b and 02:b8cd):
  15. //
  16. // https://www.dropbox.com/s/zve9f9qe9p30i0y/Pokemon%20Yellow%20ZZAZZ%20Cracker3.sn2?dl=1
  17. //
  18. //
  19. // After that, knowing exactly what to look for, I wrote this program to brute-force all
  20. // keys until I found one that gave this derived key.
  21. //
  22. // Others have observed that there's no need to brute-force once you have the derived key,
  23. // since the algorithm can be reversed from this point. The more you know :)
  24.  
  25. #include <cmath>
  26. #include <cstdio>
  27.  
  28. typedef long long llong;
  29. typedef unsigned char u8;
  30.  
  31. u8 xorVals[] = {
  32. 0x7d, 0xbc, 0x5d, 0x92, 0xc7, 0x66, 0xfb, 0x16, 0xb3, 0xc7
  33. };
  34.  
  35. u8 cipher[] = {
  36. 0x6d, 0xe5, 0x9a, 0x4c, 0xc7, 0x35, 0x1a, 0x3b,
  37. 0x78, 0xfb, 0x02, 0x84, 0x7b, 0x4b, 0x4a, 0xc0,
  38. 0x6c, 0x9b, 0x36, 0x1f, 0x34, 0x4d, 0xce, 0x24,
  39. 0xb9, 0xe0, 0x29, 0x54, 0x99, 0x67, 0x19, 0x21,
  40. 0x73, 0xcb, 0x57, 0x46, 0x2f, 0xdf, 0x5e, 0x43,
  41. 0x72, 0x7a, 0x28, 0xb0, 0x0f, 0xf6, 0x49, 0xe2,
  42. 0x12, 0xf0, 0x09, 0x44, 0xcd, 0x69, 0x95, 0x6b,
  43. 0xd3, 0xd1, 0xe6, 0x87, 0x92, 0xf7, 0xdd, 0x89,
  44. 0xc2, 0x63, 0xea, 0x1d, 0xbb, 0xa7, 0x0a, 0x48,
  45. 0x93, 0x90, 0xc1, 0x08, 0x14, 0x1b, 0x79, 0x91,
  46. 0x65, 0xf8, 0x0d, 0xd8, 0xd0, 0x47, 0xe1, 0xf9,
  47. 0x15, 0x9e, 0x05, 0x41, 0xc8, 0xb7, 0x0e, 0x7e,
  48. 0x22, 0xe9, 0xda, 0xb1, 0x62, 0x13, 0x26, 0x42,
  49. 0xab, 0xd4, 0x5c, 0x4f, 0x74, 0xc4, 0x04, 0x66,
  50. 0xd6, 0x5f, 0x38, 0x4e, 0x10, 0xa5, 0x75, 0x52,
  51. 0xaa, 0xfe, 0xf2, 0xa3, 0x70, 0x25, 0x82, 0x3a,
  52. 0x0c, 0x9d, 0x97, 0x56, 0x7d, 0xd5, 0xa4, 0xe8,
  53. 0xaf, 0x11, 0xb8, 0x33, 0xe4, 0xf4, 0x3e, 0x60,
  54. 0xcc, 0x5a, 0xfd, 0x71, 0xde, 0x94, 0x7f, 0x40,
  55. 0x53, 0xd7, 0xf3, 0x03, 0x96, 0xbf, 0x17, 0x2c,
  56. 0x98, 0xf5, 0x50, 0x8a, 0x88, 0x59, 0xac, 0x6e,
  57. 0x8e, 0x77, 0xc5, 0x58, 0x8d, 0xc9, 0xb5, 0xbe,
  58. 0x3f, 0xec, 0xa2, 0xbc, 0xa0, 0x23, 0x0b, 0x85,
  59. 0xb2, 0x86, 0x07, 0x61, 0xd9, 0xa1, 0x8f, 0x7c,
  60. 0x01, 0x64, 0xad, 0x3c, 0xff, 0x06, 0x8b, 0xa8,
  61. 0xe3, 0x76, 0x31, 0x80, 0xef, 0x81, 0x51, 0x32,
  62. 0x45, 0xdb, 0x3d, 0x1e, 0x20, 0xba, 0x8c, 0x27,
  63. 0x30, 0x6a, 0xd2, 0xb3, 0x18, 0xb4, 0xc6, 0xfc,
  64. 0x55, 0x1c, 0xdc, 0xeb, 0xae, 0xf1, 0xa6, 0xca,
  65. 0x6f, 0x5b, 0x9f, 0x16, 0x9c, 0xcf, 0xb6, 0xee,
  66. 0x39, 0xa9, 0x2a, 0x68, 0x37, 0xfa, 0x5d, 0x83,
  67. 0x00, 0x2d, 0xed, 0x2e, 0x2b, 0xe7, 0xbd, 0xc3,
  68. };
  69.  
  70. void printDigits(u8* d) {
  71. for (int i=0;i<10;i++)
  72. printf(" %d", (int)d[i]);
  73. printf("\n");
  74. }
  75.  
  76. int main() {
  77. int oldVal = -1;
  78.  
  79. for (llong val=0; val<pow(10,10); val++) {
  80. u8 origDigits[10];
  81. u8 digits[10];
  82.  
  83. llong v = val;
  84. for (int i=0;i<10;i++) {
  85. digits[i] = v%10;
  86. v /= 10;
  87.  
  88. origDigits[i] = digits[i];
  89. digits[i] += 0xf6;
  90. }
  91.  
  92. if (digits[6] != oldVal) {
  93. printf("Trying: ");
  94. printDigits(origDigits);
  95. oldVal = digits[6];
  96. }
  97.  
  98. for (int i=0; i<0x19; i++) {
  99. u8 b = digits[9];
  100.  
  101. for (int j=0; j<10; j++) {
  102. u8 v = (digits[j]>>1) | ((digits[j]&1)<<7);
  103. v ^= 0x5c;
  104. v += 0x1e;
  105. v = cipher[(int)v];
  106. v ^= b;
  107. b = v;
  108. digits[j] = v;
  109. }
  110. }
  111.  
  112. bool good=true;
  113. for (int i=0;i<10;i++) {
  114. if (digits[i] != xorVals[i]) {
  115. good = false;
  116. break;
  117. }
  118. }
  119.  
  120. if (good) {
  121. printf("Answer found:");
  122. for (int i=0;i<10;i++)
  123. printf(" %d", (int)origDigits[i]);
  124. printf("\n");
  125. return 0;
  126. }
  127. }
  128.  
  129. printf("No answer found...\n");
  130. return 0;
  131. }
Add Comment
Please, Sign In to add comment