-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
139 lines (102 loc) · 3.64 KB
/
Main.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include "aes_cbc.hpp"
#include "aes_ecb.hpp"
#include "aes_gcm.hpp"
#include "ec_algorithm.hpp"
#include "ec_digital_signature.hpp"
#include "rsa_algorithm.hpp"
#include "rsa_digital_signature.hpp"
int ChooseAlgorithm();
int ChooseKeySize(int);
void RunAlgorithm(int, int);
int main() {
//choose algorithm to run
int user_choice = ChooseAlgorithm();
if(user_choice >= 1 && user_choice <= 7) {
//choose Key Size
int keysize = ChooseKeySize(user_choice);
if(keysize != 0 || keysize == 1) {
//run the specified algorithm with key size.
RunAlgorithm(user_choice, keysize);
} else {
std::cout << "Invalid key size for the algorithm to execute.\n";
}
} else {
std::cout << "Invalid input for choosing algorithm by choice.\n";
}
}
int ChooseAlgorithm() {
int input;
std::cout << "Choose algorithm to run : \n";
std::cout << "1. AES CBC mode \n";
std::cout << "2. AES ECB mode \n";
std::cout << "3. AES GCM mode \n";
std::cout << "4. RSA \n";
std::cout << "5. Elliptic Curve \n";
std::cout << "6. DSA using Elliptic curve \n";
std::cout << "7. DSA using RSA algorithm.\n";
std::cin >> input;
return input;
}
int ChooseKeySize(int user_choice) {
std::cout << "choose key size :\n";
int keysize;
if(user_choice == 1 || user_choice == 2 || user_choice == 3) {
std::cout << "KEY SIZE : 16, 24, 32 bytes. \n";
std::cin >> keysize;
if(keysize == 16 || keysize == 24 || keysize == 32)
return keysize;
} else if(user_choice == 4 || user_choice == 7) {
std::cout << "KEY SIZE : 128, 256, 512 bytes. \n";
std::cin >> keysize;
if(keysize == 128 || keysize == 256 || keysize == 512)
return keysize;
} else if(user_choice == 5 || user_choice == 6) {
std::cout << "KEY SIZE will be based on Elliptic Curve used in the algorithm. \n\n";
return 1;
} else {
std::cout << " Sorry! Invalid input for key size.\n";
}
return 0;
}
void RunAlgorithm(int user_choice, int keysize) {
std::cout << std::endl;
if(user_choice == 1) {
std::cout << "Running AES in cbc mode : \n";
AESCbcAlgorithm* aes_cbc = new AESCbcAlgorithm();
aes_cbc->RunAESCbcAlgorithm(keysize);
delete aes_cbc;
} else if(user_choice == 2) {
std::cout << "Running AES in ecb mode : \n";
AESEcbAlgorithm* aes_ecb = new AESEcbAlgorithm();
aes_ecb->RunAESEcbAlgorithm(keysize);
delete aes_ecb;
} else if(user_choice == 3) {
std::cout << "Running AES in gcm mode : \n";
AESGcmAlgorithm* aes_gcm = new AESGcmAlgorithm();
aes_gcm->RunAESGcmAlgorithm(keysize);
delete aes_gcm;
} else if(user_choice == 4) {
std::cout << "Running RSA algorithm : \n";
RSAAlgorithm* rsa = new RSAAlgorithm();
rsa->RunRSAAlgorithm(keysize);
delete rsa;
} else if(user_choice == 5) {
std::cout << "Running EC algorithm : \n";
ECAlgorithm* ec = new ECAlgorithm();
ec->RunECAlgorithm();
delete ec;
} else if(user_choice == 6) {
std::cout << "Running EC DSA algorithm : \n";
ECDigitalSignature* ecdsa = new ECDigitalSignature();
ecdsa->RunECDSA();
delete ecdsa;
} else if (user_choice == 7) {
std::cout << "Running DSA using RSA algorithm : \n";
RSADigitalSignature* rsa_dsa = new RSADigitalSignature();
rsa_dsa->RunRSADigitalSignature(keysize);
delete rsa_dsa;
} else {
std::cout << " Sorry! Invalid input.\n";
}
}