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
|
int Decryption(char *save, int key, char ExtractedFile[])
{
char line[10000];
ofstream EncryptFile(save);
ifstream EncryptedFile;
EncryptedFile.open(ExtractedFile);
if (EncryptedFile.is_open())
{
while (!EncryptedFile.eof())
{
EncryptedFile.getline(line, 10000);
strlwr(line);
int index = 0,
addition = 0;
char newchar;
while (line[index] != 0)
{
newchar = line[index];
if (isalpha(line[index]))
{
newchar -= key;
if (newchar < 'a')
{
addition = key % 26;
newchar = 'z' - addition;
}
}
EncryptFile << newchar;
index++;
}
EncryptFile << endl;
}
}
else
{
cout << "Error" << endl;
}
cout << endl;
return 0;
}
int main()
{
bool repeat = true;
char choice,
file[100] = {},
save[100] = {},
OutputE[50] = {},
OutputD[50] = {};
int key = 123;
while (repeat == true)
{
cout << "Would you like to encrypt or decrypt your document?" << endl;
cout << "Enter E for encrypt and D for decrypt: ";
cin >> choice;
if (choice == 'E' || choice == 'e')
{
cout << "What file would you like to use?: <<<Encoding.txt>>>";
cin >> file;
cout << "What is the name of the file you wish to save your encryped text to? " << endl;
cout << "Any spaces should be input as '_' " << endl;
cout << "Type '.txt' at the end to save to a word document: ";
cin >> OutputE;
cout << "Please enter a string of numbers as your encryption key." << endl;
cin >> key;
Encrypt(file, key, OutputE);
cout << "Remember! Your encryption key is <" << key << ">. Dont forget it!" << endl;
repeat = false;
}
else if (choice == 'D' || choice == 'd')
{
cout << "What file would you like to decrypt? Please include the extention: ";
cin >> OutputE;
cout << "What is the name of the file you wish to save your decryped text to? " << endl;
cout << "Any spaces should be input as '_' " << endl;
cout << "Type '.txt' at the end to save to a word document: ";
cin >> save;
cout << "To decrypt your file, please enter your key: ";
cin >> key;
Decryption(save, key, OutputD);
repeat = false;
}
else
{
cout << "That is an invalid move\n" << endl;
repeat = true;
}
}
return 0;
}
|