/
crypto.h
108 lines (78 loc) · 2.53 KB
/
crypto.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//CryptoPals Crypto Library
//Abstract Class for the CryptoPals library
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <fstream>
#include <vector>
#include <math.h>
#include <map>
// #include <openssl/aes.h>
using namespace std;
#define INT_MAX 1000000
class CryptoLib
{
public:
//Constructor
CryptoLib();
//Hashmap that contains hex key and binary values
map<char, string> gen_hex_table();
//Convert hex to string
string con_hex_2_bin(string hexStr);
//Add spaces between strings
string add_spaces(string str, int spaces);
//Reverse string
string reverse_string(string str);
//Convert binary to decimal
vector<int> con_bin_2_dec(string str, double power);
//Convert decimal to binary
string con_dec_2_bin(int decimal);
//Convert decimal to ASCII
string con_dec_2_ascii(vector<int> v);
//Convert ASCII to HEX
string con_ascii_2_hex(string str);
//Convert HEX to ASCII
string con_hex_2_ascii(string str);
//Convert Hex to Base64
string con_hex_2_b64(string str);
//Convert Base64 to Hex
string con_b64_2_hex(string str);
//Hamming Distance
int hamming_distance(string str1, string str2);
//Base64 Encoder - Version 2
string b64_encode(string str);
//Base64 Decoder - Version 2
string b64_decode(string str);
//Base64 Decoder - Version 3
string b64_to_ascii(string str);
//Single Byte XOR
string singleByteXOR(string str);
//Single Byte XOR V2 - modified version of the above method
string singleByteXOR_V2(string str, char key);
//Return the Single Byte XOR key via Bruteforce -- modified version of challenge 4
char singleByteXOR_Bruteforce_key(string cipherBlock);
//Guess Key length of the cipher -- used for Challenge 6
int guess_key_length(string str);
//Detect Single Byte XOR
string detectSingleByteXOR(vector<int> maxV);
//Fixed XOR
string fixedXOR(string str1, string str2);
//Repeating Key XOR
string repeatingKeyXOR(string str, string key);
//Detect ECB Mode in AES Cipher
bool detect_ecb_mode(string str, int keyLength);
//Return Character frequency of a string
map<char, int> frequency_table(string str);
//Return character with the highest frequency
char ret_high_freq_char(map<char, int> m);
//Return integer with the highest frequency of alphabets
int high_frequency_count(map<char,int> m);
//Print vector
void print_vector(vector<int> v);
//Print Hashmap
void print_map(map <char,string> m);
void print_map(map <char,int> m);
void print_map(map <string,char> m);
};