-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path*subs_cipher.cpp
More file actions
31 lines (29 loc) · 961 Bytes
/
Copy path*subs_cipher.cpp
File metadata and controls
31 lines (29 loc) · 961 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
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Hello! It is substitution cipher." << endl
<< "Enter your message to encrypt it: ";
string alphabet {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string key {"qwertyuiopasdfghjklzxcvbnmMNBVCXZLKJHGFDSAPOIUYTREWQ"};
string message;
getline(cin, message);
int position {0};
cout << "Encrypting message..." << endl
<< "Encrypted message: ";
for (size_t i = 0; i < message.length(); i++)
{
for (size_t j = 0; j < alphabet.length(); j++)
{
if (message.at(i) == alphabet.at(j)) {
position = alphabet.find(message.at(i));
message.at(i) = key.at(position);
break;
}
}
cout << message.at(i);
}
cout << "\nHave a nice day!" << endl;
system("pause");
return 0;
}