-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoly_Alpha_Key.cpp
62 lines (49 loc) · 992 Bytes
/
Poly_Alpha_Key.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define start_ch '\0'
string k="", s;
ll key;
char table[128][128];
void create_table()
{
for(ll i=0;i<128;i++)
{
for(ll j=0;j<128;j++)
{
table[i][j]=((i+j+key)%128)+start_ch;
}}
}
void encryption(string s)
{
cout << "Cipher Text: \n";
for(ll i=0; i<s.size(); i++)
{
k+= (table[(s[i]-start_ch)][i%128]);
}
cout << k;
cout << '\n';
}
void decryption()
{
cout << "Plain Text: \n";
string tmp="";
for(ll i=0; i<k.size();i++){
for(ll j=0;j<128;j++)
{
if(table[j][i%128]==k[i]) {tmp+= (start_ch+j);}
}
}
cout << tmp << '\n';
}
int main()
{
cout << "Enter the key: ";
cin >> key;
getchar();
create_table();
cout <<"Enter text: \n";
getline(cin, s);
encryption (s);
decryption ();
}