In Cryptography, a Caesar cipher, which is said to have been used by Julius Caesar to communicate with his army, is one of the simplest and most widely known encryption techniques.
Caesar is considered to be one of the first persons to have ever employed encryption for the sake of securing messages. Caesar decided that shifting each letter in the message would be his standard algorithm, and so he informed all of his generals of his decision, and was then able to send them secured messages. Using the Caesar Shift (3 to the right), the message,

By Matt_Crypto – http://en.wikipedia.org/wiki/File:Caesar3.png, Public Domain, https://commons.wikimedia.org/w/index.php?curid=30693472
Following a simple Code in C++ to implement a Caesar Cipher :
#include <iostream> |
#include <string> |
using namespace std; |
char caesar( char ); |
int main() |
{ |
string input; |
do { |
cout << "Enter ciphertext and press enter to continue." << endl; |
cout << "Enter blank line to quit." << endl; |
getline(cin, input); |
string output = ""; |
for(int i = 0; i < input.length(); i++) |
{ |
output += caesar(input[i]); |
} |
cout << output << endl; |
} while (input.length() != 0); |
} //end of main function |
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; |
} |
The isalpha() function checks whether the input is an alphabet or not….in case of a number or special character , the program should return the same number/character.
The above program would Encrypt “ABCDE” as “NOPQR” and amazingly the same code can be used to Decrypt “NOPQR” as “ABCDE”!!!
Try changing this line of code “c = (((c-65)+13) % 26) + 65;” to get a different outputs (Ascii of A + 13 = Ascii of N) .
You can also use a variable like “i” or an expression like “2i-5” instead of 13….Make your own KEY !!!

Source: https://commons.wikimedia.org/wiki/File:CipherDisk2000.jpg
6 comments. Leave new
Awesome bro !
Thanks Raj!!
WOW Umair this will help me in my css exam ty!!!!!!!
Welx beta
Sir of Caesar Cipher is named after Julius Caesar then is Brute forcing named after Brutus sir pls answer big fan
Yes big fan youre correct