Skip to content

Commit d232dec

Browse files
committed
KnownPlainTextVulnerability example minor fix
1 parent 62e0a15 commit d232dec

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

examples/KnownPlainTextVulnerability/KnownPlainTextVulnerability.ino

+13-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ void setup() {
3737
void loop() {
3838
Serial.print("Salt: ");
3939
// Set a new salt
40-
if(cape.salt != 127) cape.salt++;
41-
else cape.salt = 0;
40+
cape.salt++;
4241
Serial.print(cape.salt, DEC);
4342

4443
Serial.print(" Encryption key: ");
@@ -52,7 +51,15 @@ void loop() {
5251
for(int i = 0; i < 10; i++)
5352
Serial.print((char)destination[i]);
5453

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: ");
5663
for(uint8_t i = 0; i < 10; i++)
5764
calculated_key[(i ^ cape.salt ^ reduced_key) % 10] =
5865
(destination[i] ^ source[i] ^ cape.salt ^ reduced_key ^ i);
@@ -61,6 +68,8 @@ void loop() {
6168
Serial.print((char)calculated_key[i]);
6269
Serial.println();
6370

71+
// More than one salt value generates the key originally used (bad)
72+
6473
for(uint8_t i = 0; i < 10; i++) {
6574
if(calculated_key[i] != key[i]) break;
6675
if(i == 9) {
@@ -69,8 +78,8 @@ void loop() {
6978
}
7079
}
7180

72-
7381
// Erase buffer
82+
7483
for(int i = 0; i < 10; i++) {
7584
source[i] = '0';
7685
destination[i] = 0;

0 commit comments

Comments
 (0)