$ g++ CaesarCipher.cpp $ a.out Enter cipertext and press enter to continue. Enter blank line to quit. Sanfoundry FNASBHAQEL Enter cipertext and press enter to continue. Enter blank line to quit. ------------------ (program exited with code: 0) Press return to continue
Users Online
· Guests Online: 108
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C++ Program to Implement Caesar Cipher
C++ Program to Implement Caesar Cipher
This is a C++ Program to implement Caesar Cipher Encryption algorithm. This is the simplest of all, where every character of the message is replaced by its next 3rd character.
Here is source code of the C++ Program to Implement Caesar Cypher. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
-
#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;
-
}
Output:
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.