-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.cpp
More file actions
103 lines (73 loc) · 1.95 KB
/
encrypt.cpp
File metadata and controls
103 lines (73 loc) · 1.95 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include "ReallyLongInt.hpp"
#include "numberTheory.hpp"
using namespace std;
int main(int argc, char *argv[])
{
if(argc!=4)
{
cout<<"Please enter the key file, input file and output file as command line arguments"<<endl;
return 1;
}
ifstream inFile;
ofstream outFile;
inFile.open(argv[1]);
outFile.open(argv[3]);
if (!inFile) {
cerr << "Unable to open file"<<endl;
exit(1); // call system to stop
}
//ReallyLongInt x; //to store ASCII value
//string in1;
//string in2;
//inFile[0]>>in1;
//inFile[1]>>in2;
ReallyLongInt e; //(stoll(in1));
ReallyLongInt n; //(stoll(in2));
string z;
int idx=0;
while(inFile>>z)
{
if(idx==0)
e=stoll(z);
else if(idx==1)
n=stoll(z);
//n=stoll(inFile[2]);
idx++;
}
inFile.close();
//loop over characters in message
inFile.open(argv[2]);
if (!inFile) {
cerr << "Unable to open file"<<endl;
exit(1); // call system to stop
}
int ascii; //ASCII value
ReallyLongInt y;
char ch;
while(inFile>>ch)
{
cout<<"Character is: "<<ch<<endl;
cout<<"Value of e: "<<e.toString()<<endl;
cout<<"Value of n: "<<n.toString()<<endl;
ascii=(int)ch; //character to ASCII value
cout<<"ascii value of char is: "<<ascii<<endl;
ReallyLongInt x(ascii);
y=(x.exp(e))%n;
cout<<"checking exp: "<<(x.exp(e)).toString()<<endl;
//cout<<"value of y: "<<y.toString()<<endl;
long long character=stoll(y.toString(),nullptr,10); //converting string->ll
cout<<"character long long: "<<character<<endl;
char c=(char)character;
cout<<"char c is: "<<c<<endl;
//char c=static_cast<char>(y);
outFile<<c;
cout<<"------------------------"<<endl;
}
inFile.close();
outFile.close();
}