-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher5.cpp
More file actions
94 lines (78 loc) · 2.71 KB
/
cipher5.cpp
File metadata and controls
94 lines (78 loc) · 2.71 KB
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
//FCI - Programming1- 2018 - Assignment 2
//program name: simple substitution cipher.cpp
//Last modification date: February 27,2018
//Hanan Mohamed, 20170375, G14
//Teaching Assistant: Eng.Dosoki
//purpose: cipher and decipher by getting a key from user that consists of 5 characters and exchange them with the first 5 characters in plain alphabet, then list down the remaining letters in order.
#include <iostream>
using namespace std;
int main()
{
string plain = "abcdefghijklmnopqrstuvwxyz";
string cipher;
string key;
string text;
int choice;
cout<< "what do you want to do?"<<endl<<"1. cipher"<<endl<<"2.Decipher"<<endl;
cin>>choice;
if (choice == 1){
cout<<"Enter your key"<<endl;
cin>>key;
cout<<key<<"";
for(int i = 0; i<26; i++){
for(int j = 0 ; j<26; j++){
if (i == j){
if (plain[i] !=key[0] && plain[i] != key[1] && plain[i] != key[2] && plain[i] != key[3] && plain[i] != key[4]){
cipher[j] = plain[i];
cout<<cipher[j];
}
}
}
}
}
for(int i = 0; i<26; i++){
for(int j =0; j<26; j++){
if (i == j){
if(plain[i] !=key[0] && plain[i] != key[1] && plain[i] != key[2] && plain[i] != key[3] && plain[i] != key[4]){
cipher[0] = key[0];
cipher[1] = key[1];
cipher[2] = key[2];
cipher[3] = key[3];
cipher[4] = key[4];
cipher[j]=plain[i];
cout<<endl;
cout<<endl<<"please enter your text"<<endl;
cin.get();
getline(cin, text);
for(int z = 0; z<=text.length()-1;z++){
text[z] = cipher[z];
cout<<text[z];
}
}
}
}
}
if (choice ==2){
cout<<"Enter your key"<<endl;
cin>>key;
for(int i = 0; i<26; i++){
for(int j =0; j<26; j++){
if (i == j){
plain[0] = key[0];
plain[1] = key[1];
plain[2] = key[2];
plain[3] = key[3];
plain[4] = key[4];
plain[i] = cipher[j];
cout<<endl<<"please enter your text"<<endl;
cin.get();
getline(cin, text);
for(int z = 0; z<=text.length()-1;z++){
text[z] = cipher[z];
cout<<text[z];
}
}
}
}
}
}