-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrsa.cpp
44 lines (39 loc) · 1.19 KB
/
rsa.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
#include <iostream>
#include <string>
#include <cstring>
#include "cipher.h"
#include "key_pair_generator.h"
using namespace std;
// argv[0] - name of executable file of this program
// argv[1] - mode of program:
// --generate-keys - generating keys
// --decode - decoding using id_rsa (requires filename)
// --code - coding using id_rsa.pub (requires filename)
// argv[2] - name of source file (if needed) or length of prime number for key.
// argv[3] - name of destination file (if needed)
int main (int argc, char const* argv[])
{
if (argc == 3) {
if (!strcmp(argv[1], "--generate-keys")) {// generates keys and saves to id_rsa.pub i id_rsa in current folder
srand( time(NULL) );
KeyPairGenerator generator( atoi(argv[2]) );
generator.generate();
}
}
else if (argc == 4) {
string source(argv[2]), destination(argv[3]);
Cipher cipher(source, destination);
if (!strcmp(argv[1], "--code")) {// codes using public key from id_rsa.pub
cipher.encrypt();
}
else if (!strcmp(argv[1], "--decode")) {// decodes using private key from id_rsa
cipher.decrypt();
}
else
cout << "Unknown argument." << endl;
}
else {
cout << "Wrong number of arguments." << endl;
}
return 0;
}