-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset2_challenge16.cpp
43 lines (34 loc) · 1.04 KB
/
set2_challenge16.cpp
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
#include "cryptopals_uri.h"
#include <sstream>
#include <iostream>
void test_cipher(byte_array cipher) {
if (uri_decrypt_cbc(cipher)) {
std::cout << "Admin access granted!" << std::endl;
} else {
std::cout << "Denied!!!" << std::endl;
}
}
int main(int argc, char ** argv) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " seed" << std::endl;
std::cerr << "CBC bitflipping attack" << std::endl;
return 1;
}
std::istringstream ss(argv[1]);
int seed;
if (!(ss >> seed)) {
std::cerr << "Invalid number: " << argv[1] << std::endl;
return 1;
}
init_random_encrypt(seed);
std::string s("3admin5true");
byte_array cipher = uri_encrypt_cbc(s);
test_cipher(cipher);
std::cout << "Manipulating a few bits in the cipher before attempting decryption again..." << std::endl;
cipher.bytes[16] ^= '3' ^ ';';
cipher.bytes[22] ^= '5' ^ '=';
test_cipher(cipher);
free_byte_array(cipher);
cleanup_random_encrypt();
return 0;
}