@@ -37,8 +37,7 @@ void setup() {
37
37
void loop () {
38
38
Serial.print (" Salt: " );
39
39
// Set a new salt
40
- if (cape.salt != 127 ) cape.salt ++;
41
- else cape.salt = 0 ;
40
+ cape.salt ++;
42
41
Serial.print (cape.salt , DEC);
43
42
44
43
Serial.print (" Encryption key: " );
@@ -52,7 +51,15 @@ void loop() {
52
51
for (int i = 0 ; i < 10 ; i++)
53
52
Serial.print ((char )destination[i]);
54
53
55
- Serial.print (" Brute force key: " );
54
+ /* Simulating known plain text attack with the following assumptions:
55
+ - Known plaintext
56
+ - Known ciphertext
57
+ - Known key length (can be obtained using brute force quickly)
58
+ - Known function used (hash/encrypt)
59
+ - Known reduced key (can be obtained using brute force quickly)
60
+ - Salt is obtained using brute force: */
61
+
62
+ Serial.print (" Calculate key: " );
56
63
for (uint8_t i = 0 ; i < 10 ; i++)
57
64
calculated_key[(i ^ cape.salt ^ reduced_key) % 10 ] =
58
65
(destination[i] ^ source[i] ^ cape.salt ^ reduced_key ^ i);
@@ -61,6 +68,8 @@ void loop() {
61
68
Serial.print ((char )calculated_key[i]);
62
69
Serial.println ();
63
70
71
+ // More than one salt value generates the key originally used (bad)
72
+
64
73
for (uint8_t i = 0 ; i < 10 ; i++) {
65
74
if (calculated_key[i] != key[i]) break ;
66
75
if (i == 9 ) {
@@ -69,8 +78,8 @@ void loop() {
69
78
}
70
79
}
71
80
72
-
73
81
// Erase buffer
82
+
74
83
for (int i = 0 ; i < 10 ; i++) {
75
84
source[i] = ' 0' ;
76
85
destination[i] = 0 ;
0 commit comments