Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ program to brute-force the key for the 3rd cracker challenge in ZZAZZ's April Fool's 2018.
- //
- // The "xorvals" (derived key) were determined manually; I observed that after the key was
- // hashed up, each byte had no effect on the others, meaning that I could try all 256
- // values for a particular byte and choose the one that looked most promising. The result,
- // was that I built up the image one set of lines at a time. Even when I had nothing to go on,
- // it was easy to pick the correct bytes due to how much blank space they produced (compared
- // to random noise).
- //
- // This part was accomplished by hacking the code, because I'm better at writing gb-z80
- // than c++. :)
- //
- // I wrote assembly to cycle through all 256 values quickly. Try this savestate to see it
- // in action (custom code at 02:b89b and 02:b8cd):
- //
- // https://www.dropbox.com/s/zve9f9qe9p30i0y/Pokemon%20Yellow%20ZZAZZ%20Cracker3.sn2?dl=1
- //
- //
- // After that, knowing exactly what to look for, I wrote this program to brute-force all
- // keys until I found one that gave this derived key.
- //
- // Others have observed that there's no need to brute-force once you have the derived key,
- // since the algorithm can be reversed from this point. The more you know :)
- #include <cmath>
- #include <cstdio>
- typedef long long llong;
- typedef unsigned char u8;
- u8 xorVals[] = {
- 0x7d, 0xbc, 0x5d, 0x92, 0xc7, 0x66, 0xfb, 0x16, 0xb3, 0xc7
- };
- u8 cipher[] = {
- 0x6d, 0xe5, 0x9a, 0x4c, 0xc7, 0x35, 0x1a, 0x3b,
- 0x78, 0xfb, 0x02, 0x84, 0x7b, 0x4b, 0x4a, 0xc0,
- 0x6c, 0x9b, 0x36, 0x1f, 0x34, 0x4d, 0xce, 0x24,
- 0xb9, 0xe0, 0x29, 0x54, 0x99, 0x67, 0x19, 0x21,
- 0x73, 0xcb, 0x57, 0x46, 0x2f, 0xdf, 0x5e, 0x43,
- 0x72, 0x7a, 0x28, 0xb0, 0x0f, 0xf6, 0x49, 0xe2,
- 0x12, 0xf0, 0x09, 0x44, 0xcd, 0x69, 0x95, 0x6b,
- 0xd3, 0xd1, 0xe6, 0x87, 0x92, 0xf7, 0xdd, 0x89,
- 0xc2, 0x63, 0xea, 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, 0x37, 0xfa, 0x5d, 0x83,
- 0x00, 0x2d, 0xed, 0x2e, 0x2b, 0xe7, 0xbd, 0xc3,
- };
- void printDigits(u8* d) {
- for (int i=0;i<10;i++)
- printf(" %d", (int)d[i]);
- printf("\n");
- }
- int main() {
- int oldVal = -1;
- for (llong val=0; val<pow(10,10); val++) {
- u8 origDigits[10];
- u8 digits[10];
- llong v = val;
- for (int i=0;i<10;i++) {
- digits[i] = v%10;
- v /= 10;
- origDigits[i] = digits[i];
- digits[i] += 0xf6;
- }
- if (digits[6] != oldVal) {
- printf("Trying: ");
- printDigits(origDigits);
- oldVal = digits[6];
- }
- for (int i=0; i<0x19; i++) {
- u8 b = digits[9];
- for (int j=0; j<10; j++) {
- u8 v = (digits[j]>>1) | ((digits[j]&1)<<7);
- v ^= 0x5c;
- v += 0x1e;
- v = cipher[(int)v];
- v ^= b;
- b = v;
- digits[j] = v;
- }
- }
- bool good=true;
- for (int i=0;i<10;i++) {
- if (digits[i] != xorVals[i]) {
- good = false;
- break;
- }
- }
- if (good) {
- printf("Answer found:");
- for (int i=0;i<10;i++)
- printf(" %d", (int)origDigits[i]);
- printf("\n");
- return 0;
- }
- }
- printf("No answer found...\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment