-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge8.cpp
More file actions
41 lines (32 loc) · 948 Bytes
/
challenge8.cpp
File metadata and controls
41 lines (32 loc) · 948 Bytes
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
/*
Detect AES in ECB mode
In this file are a bunch of hex-encoded ciphertexts.
One of them has been encrypted with ECB.
Detect it.
Remember that the problem with ECB is that it is stateless and deterministic; the same 16 byte plaintext block will always produce the same 16 byte ciphertext.
*/
#include "challenges.h"
#include "encoding_utils.h"
#include "aes.h"
std::string challenge8() {
std::ifstream file("8.txt");
if (!file.is_open()) {
return "File 8.txt failed to open";
}
std::string line;
std::vector<std::string> matches;
while (std::getline(file, line)) {
if (hasRepeatingBlocks(hexToText(line), 16)) {
matches.push_back(line);
}
}
file.close();
switch (matches.size()) {
case 0 :
return "No ECB encoded ciphertext found.";
case 1:
return matches.at(0);
default:
return "Multiple ECB encoded ciphertexts found.";
}
}