ceaser cipher

Write your question here.
code for ceaser chiper
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
#include <iostream>
#include <string>
using namespace std;
char caesar( char );
int main()
{
    string input;
    do {
        cout << "Enter cipertext and press enter to continue." << endl;
        cout << "Enter blank line to quit." << endl;
        getline(cin, input);
        string output = "";
        for(int x = 0; x < input.length(); x++)
        {
            output += caesar(input[x]);
        }
        cout << output << endl;
    } while (!input.length() == 0);
}  //end main
 
char caesar( char c )
{
    if( isalpha(c) )
    {
        c = toupper(c); //use upper to keep from having to use two seperate for A..Z a..z
        c = (((c-65)+13) % 26) + 65;
    }
    //if c isn't alpha, just send it back.
    return c;
}
Topic archived. No new replies allowed.