-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass2.hpp
54 lines (48 loc) · 1.65 KB
/
Class2.hpp
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
#ifndef CLASS2_HPP_INCLUDED
#define CLASS2_HPP_INCLUDED
#include "Class.hpp"
class decrypter: public encrypter{
public:
//Retrieves key and decrypts encrypted files
void decypher(){
//open files
std::ifstream theKey("keycode.txt");
std::ifstream theMess("encryptedFile.txt");
if (theMess.is_open() && theKey.is_open()){
//reads lines char by char and converts the key to an int
while(!theMess.eof()){
theKey.get(keyChar);
theMess.get(jumChar);
keyInt= keyChar- '0';
//std::cerr<< keyInt<< std::endl;
// uses the info above to navigate the alphArr and decode the message
for(signed int j= 0; j< alphArrSize; ++j){
if(jumChar== alphArr[j]){
int temp= (j- keyInt)% alphArrSize;
if(temp< 0){
temp+= alphArrSize;
}
actualChar= alphArr[temp];
message+= actualChar;
std::cerr<< temp << "\n";
}
}
}
message[message.length()- 1]= ' ';
std::cout<< "\nexporting File...\n";
std::ofstream defile;
defile.open ("decryptedFile.txt");
defile<< message;
std::cout<< "File decrypted!\n";
defile.close();
}else std::cout << "ERROR: missing one or more files!";
}
private:
char jumChar;
char keyChar;
char actualChar;
signed int keyInt;
std::string message;
protected:
};
#endif // CLASS2_HPP_INCLUDED