cipher

I need help with a cipher assignment where the default map is set to zywvutsrqponmlkjihgfedcba
any help will be appreciated

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
cout << " Encryption Cipher\n";
     cout << " Enter a word: \n";
     cin  >> word;


     size = word.size();
     cout << " Your word is: " << word << endl;
     cout << " Enter a map ( input 'default' to select default) \n";
     cin >> map;
     if(map == "default")
     {
      map = "zywvutsrqponmlkjihgfedcba";
     }
     for(int temp =0; temp < size; temp++)
     {
         if( word[temp] >= 'a' && word[temp] <= 'z')
   {
   word[temp] = (tolower(word[temp]));
   word[temp] += map[temp] - 'z';
    word[temp]++;

   }
         else
         {
             cout << " Error\n";
             return 0;
         }
    }
     cout << " Encrypted: " << word << endl;
@Nikki365

Doesn't your map string need an 'x' in it, between the 'y' and 'w'?
Pull some ideas out of this, perhaps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::cin;

int main()
{
  const string cipher("zyxwvutsrqponmlkjihgfedcba");
  string userInput;
  cout << "Enter word: ";
  cin >> userInput;
  for (const auto & letter: userInput)
  {
    cout << cipher[toupper(letter) - 65];
  }
  cout << '\n';
}


http://www.ascii-code.com/
http://www.cplusplus.com/reference/cctype/toupper/
Topic archived. No new replies allowed.