From cb990c73c478c1bb40d749d0f4e52c10a9ac80fd Mon Sep 17 00:00:00 2001 From: Benedict Date: Sat, 13 Aug 2016 17:57:51 +0200 Subject: set3, challenge 24 completed --- lib/lib3.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/lib3.h | 6 +++++ set3/task24.c | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 set3/task24.c diff --git a/lib/lib3.c b/lib/lib3.c index e976fd1..150c6ea 100644 --- a/lib/lib3.c +++ b/lib/lib3.c @@ -203,3 +203,81 @@ int unshift_left_xor(int number, int shifts, unsigned int mask) return restore; } + +int mt_19937_stream_cipher(char *in, int length_in, char *out, int seed) +{ + struct mt_19937_state mt_state; + char keystream; + int i, tmp; + + mt_19937_seed(seed, &mt_state); + + for(i=0;i + +/** + * One should not restore the internal state of the MT. Given 624 bytes of + * input this would be straight forward. + * Instead one should restore more or less the first state (the seed from + * which this states arrived). To restore a previous state of the MT is + * possible. You have to go so far back, how long your ciphertext is and + * how much states you would need to encrpyt it. + * + * Since it is a 16 bit seed, one can also brute force it with 2^16 + * possible values...within seconds! exhautive search Yeah! + * Theoritcal we only need 2^(16/2) values because of birthday paradox + * + **/ + +int main() +{ + srand(time(NULL)); + // try to decrypt + char plaintext[] = "Hallo du da wie geht es dir Knallkopp"; + char *ciphertext = malloc(strlen(plaintext)); + + int length_ciphertext = mt_19937_stream_cipher_oracle(plaintext, + strlen(plaintext), ciphertext); + + char *restore_pl = malloc(length_ciphertext); + char *hex_ciphertext = malloc(length_ciphertext*2+1); + hex_binary_to_string(ciphertext, hex_ciphertext, length_ciphertext); + printf("ciphertext: %s\n", hex_ciphertext); + //mt_19937_stream_cipher(ciphertext, length_ciphertext + // decrypt it + crack_mt_19937_stream_cipher_16_bit_seed(ciphertext, length_ciphertext, + restore_pl, plaintext); + + printf("plaintext: %s\n", restore_pl); + + // crack a MT time based password token + // well do it agian with brute force + unsigned int password_token = mt_19937_password_token(); + int is_time_based = mt_19937_password_token_time_based(password_token, 1000); + + printf("password token is time based %i\n", is_time_based); + +} -- cgit v1.2.3-70-g09d2