-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyed.cpp
63 lines (53 loc) · 876 Bytes
/
keyed.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
63
#include<iostream>
using namespace std;
int main(){
string s;
cout << "Enter Plaintext: " ;
cin >> s;
int i,j,l,k=0;
l = s.length();
int bsize=5;
char encry[l];
int key[5];
cout << "Enter key: ";
for(i=0;i<5;i++)
cin >> key[i];
/*
for(i=0;i<5;i++){
encry[i] = s[key[i]-1];
}
*/
for(i=0;i<l;i=i+5){
//cout << "\n" << i << " " << endl;
int keyi = 0;
for(j=i;j<=i+5-1;j++){
//cout << j << " ";
encry[j] = s[i+key[keyi]-1];
keyi++;
}
}
cout << encry << endl;
int m;
//Decrytion
char decry[l];
int deck[5];
for(i=0;i<5;i++){
m = key[i]-1;
deck[m] = i;
}
/*for(i=0;i<5;i++)
cout << deck[i] << " ";
*/
for(i=0;i<l;i=i+5){
int keyi = 0;
for(j=i;j<=i+5-1;j++){
//cout << j << " ";
decry[j] = encry[i+deck[keyi]];
keyi++;
}
}
//cout << decry << endl;
for(i=0;i<l;i++)
cout << decry[i];
cout << endl;
}