Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <map>
- #include <algorithm>
- using namespace std;
- // Helpful Functions
- void displayVector(vector <char> v){
- for(unsigned int i=0; i<v.size(); i++){
- cout << v[i] << endl;
- }
- }
- void displayMap(map <char,char> myMap){
- map <char,char> :: iterator mitr;
- for(mitr=myMap.begin(); mitr!=myMap.end(); mitr++){
- cout << "Key: " << mitr->first << " Value: " << mitr->second << endl;
- }
- }
- int main()
- {
- // 1. Intro
- cout << "This programme is about the famous code 'Atbas'.\n";
- //2. Create the vectors that contains all the letters of Alphabets
- vector <char> alphabet = vector <char> ();
- vector <char> alphabetReversed = vector <char> ();
- for(char c='a'; c<='z'; c++){
- alphabet.push_back(c);
- }
- // 3. Create the 2'Atbas' maps: first for ciphering and the other one for deciphering
- // Encryption
- map <char,char> atbasEncryption = map <char,char> ();
- map <char,char> atbasDecryption = map <char,char> ();
- for(unsigned int i=0; i<alphabet.size(); i++){
- atbasEncryption.insert({alphabet[i],alphabet[alphabet.size()-1-i]});
- }
- cout << "Write the message you want me to cipher:\n";
- string message;
- getline(cin, message);
- string answer;
- if(message.size() == 0){
- cout << "With 0 letters, what do you expect from me to do?" << endl << endl;
- return 0;
- }
- else{
- for(unsigned int i=0; i<message.size(); i++){
- if(message[i] == ' '){
- answer += ' ';
- }
- else{
- answer += (atbasEncryption.find(message[i])->second);
- }
- }
- cout << "Message before: " << message << endl;
- cout << "Message encrypted: " << answer << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement