In: Computer Science
research the Caesar Cipher, and document your research in 2-3 pages in a Word document with illustrations in your document and provide an example of how the Caesar Cipher works while encrypting and decrypting a sample message. Also, add its history and its internal workings.
Summary of the areas to complete:
- Research the Caesar Cipher.
- Show its Encryption Method in details.
- Show its Decryption Method in details.
- Describe its History and what it was used for.
- Describe its Algorithms in details.
- Add Graphical Illustrations of its algorithms.
- Give an Example for Encrypting and Decrypting a text message.
- Write a Java, C/C++, or Python code and run it to complete the example message.
The Caesar Cipher technique is one of the earliest and simplest
method of encryption technique. It’s simply a type of substitution
cipher, i.e., each letter of a given text is replaced by a letter
some fixed number of positions down the alphabet. For example with
a shift of 1, A would be replaced by B, B would become C, and so
on. The method is apparently named after Julius Caesar, who
apparently used it to communicate with his officials.
Thus to cipher a given text we need an integer value, known as
shift which indicates the number of position each letter of the
text has been moved down.
More complex encryption schemes such as the Vigenère cipher employ the Caesar cipher as one element of the encryption process. The widely known ROT13 'encryption' is simply a Caesar cipher with an offset of 13. The Caesar cipher offers essentially no communication security, and it will be shown that it can be easily broken even by hand.
The encryption can be represented using modular arithmetic by first
transforming the letters into numbers, according to the scheme, A =
0, B = 1,…, Z = 25. Encryption of a letter by a shift n can be
described mathematically as.
(Encryption Phase with shift n)
(Decryption Phase with shift n)
Example:
Text : ABCDEFGHIJKLMNOPQRSTUVWXYZ Shift: 23 Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW Text : ATTACKATONCE Shift: 4 Cipher: EXXEGOEXSRGI
For Caesar cipher code in various programming languages, see the Implementations page.
To encipher your own messages in python, you can use the pycipher module. To install it, use pip install pycipher. To encipher messages with the Caesar cipher.
Cryptanalysis is the art of breaking codes and ciphers. The Caesar cipher is probably the easiest of all ciphers to break. Since the shift has to be a number between 1 and 25, (0 or 26 would result in an unchanged plaintext) we can simply try each possibility and see which one results in a piece of readable text. If you happen to know what a piece of the ciphertext is, or you can guess a piece, then this will allow you to immediately find the key.
If this is not possible, a more systematic approach is to calculate the frequency distribution of the letters in the cipher text. This consists of counting how many times each letter appears. Natural English text has a very distinct distribution that can be used help crack codes.
Java Code to run Ceaser Cipher Encryption and Decryption:
package com.sanfoundry.setandstring;
import java.util.Scanner;
public class CaesarCipher
{
public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
public static String encrypt(String plainText, int shiftKey)
{
plainText = plainText.toLowerCase();
String cipherText = "";
for (int i = 0; i < plainText.length(); i++)
{
int charPosition = ALPHABET.indexOf(plainText.charAt(i));
int keyVal = (shiftKey + charPosition) % 26;
char replaceVal = ALPHABET.charAt(keyVal);
cipherText += replaceVal;
}
return cipherText;
}
public static String decrypt(String cipherText, int shiftKey)
{
cipherText = cipherText.toLowerCase();
String plainText = "";
for (int i = 0; i < cipherText.length(); i++)
{
int charPosition = ALPHABET.indexOf(cipherText.charAt(i));
int keyVal = (charPosition - shiftKey) % 26;
if (keyVal < 0)
{
keyVal = ALPHABET.length() + keyVal;
}
char replaceVal = ALPHABET.charAt(keyVal);
plainText += replaceVal;
}
return plainText;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String for Encryption: ");
String message = new String();
message = sc.next();
System.out.println(encrypt(message, 3));
System.out.println(decrypt(encrypt(message, 3), 3));
sc.close();
}
}
Note: If you have any related doubts, queries, feel free to ask by commenting down below.
And if my answer suffice your requirements, then kindly upvote.
Happy Learning