-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution-01.cpp
More file actions
36 lines (36 loc) · 1011 Bytes
/
Copy pathSolution-01.cpp
File metadata and controls
36 lines (36 loc) · 1011 Bytes
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
#include <string>
#include <iostream>
using namespace std;
string ReadText()
{
string Text;
cout<<"Please enter your text : ";
getline(cin,Text);
return Text;
}
string EncryptText(string Text, short EncryptionKey)
{
for(int i = 0; i < (int)Text.length(); i++)
{
Text[i] = char((int) Text[i] + EncryptionKey);
}
return Text;
}
string DecryptText(string Text, short EncryptionKey)
{
for(int i = 0; i < (int)Text.length(); i++)
{
Text[i] = char((int) Text[i] - EncryptionKey);
}
return Text;
}
int main()
{
const short EncryptionKey = 2;
string TextBeforeEncryption = ReadText();
string TextAfterEncryption = EncryptText(TextBeforeEncryption,EncryptionKey);
string TextAfterDecryption = DecryptText(TextAfterEncryption,EncryptionKey);
cout<<"Text Before Encryption : "<<TextBeforeEncryption<<endl;
cout<<"Text After Encryption : "<<TextAfterEncryption<<endl;
cout<<"Text After Decryption : "<<TextAfterDecryption<<endl;
}