summaryrefslogtreecommitdiff
path: root/set3/task24.c
blob: e355d08554cbfad8e16af48b8734a06560302a45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "../lib/lib.h"
#include "../lib/lib2.h"
#include "../lib/lib3.h"
#include <time.h>

/**
  * 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);

}