Last active
August 29, 2015 14:13
-
-
Save Slashmolder/40e6078be1a44d84ef78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <inttypes.h> | |
void tea_decrypt (uint32_t *v, uint32_t *k) { | |
uint32_t v0=0, v1=0, sum=0; | |
uint32_t delta=0x61C88647; | |
uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; | |
do { | |
sum -= delta; | |
v0 += ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1); | |
v1 += ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3); | |
} while (sum != 0x78DDE6E4); | |
v[0] ^= v0; | |
v[1] ^= v1; | |
} | |
int main (int argc, char **argv) { | |
if (argc != 3) { | |
printf("usage: %s gateway.dg decrypted.dg\n", argv[0]); | |
return 0; | |
} | |
uint32_t base[2]; | |
uint32_t tea_key[4] = { 0x6E6629A0, 0x6F6AC2A1, 0x12B1908A, 0x1A31FDB}; | |
FILE *gateway = fopen(argv[1], "rb"); | |
FILE *decrypted = fopen(argv[2], "wb"); | |
while (fread(base, 8, 1, gateway)) { | |
tea_decrypt(base, tea_key); | |
tea_key[0] += 8; | |
fwrite(base, 8, 1, decrypted); | |
} | |
// done | |
fclose(gateway); | |
fclose(decrypted); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment