Question
Write a program to encode or decode a message using a Caesar Shift. History of the Caesar Shift Publin Domain The first documented use of
Write a program to encode or decode a message using a Caesar Shift.
History of the Caesar Shift
Publin Domain
The first documented use of a substitution cipher in military history is attributed to Julius Caesar (around 50 BCE) during the Gaelic Wars. He sent a coded message to Cicero (who was about to surrender), by substituting Greek letters for Roman letters, and later utilized a substitution cipher that became known as the Caesar Shift. Did you own a secret decoder ring or disk as a child? If so, you have probably used the Caesar Shift. So when you write your program for this assignment, be careful to whom you send coded messages. With a few lines of Java, any Caesar Shift can be broken and your secrets revealed.
Part 1: Encryption
Public Domain
- Read the Background section below to understand the Caesar Shift algorithm.
- Create a new project called 09.07 Caesar Shift Cipher in the Mod09 Assignments folder.
- Create two new classes called Encryption and CaesarTester in the newly-created project.
- Read over all the specifications and create a plan before starting to write code.
- Ask the user to input a shift key value from 0–25. Ensure the input is valid. Use the same shift key value for all instances of the Encryption class.
- Declare the alphabet as a class constant.
- Write a static method to generate the cipher alphabet based on the key.
- Display the alphabet and cipher alphabet to the screen.
- Provide a menu to allow the user to choose between encryption and decryption. After one message is processed, allow the user to continue entering more messages until he or she decides to quit.
- Ask the user to input a plaintext message.
- Display the encrypted message for the user to view.
- Write a static method to encrypt the plaintext message and return the result.
Part 2: Decryption
- Write a new class called Decryption in the current project.
- Allow the user to input a shift key value (0–25) and a cipher text message.
- You may reuse any previously-created methods or variables.
- Generate the cipher alphabet based on the key and print the alphabet to the screen.
- Write a static method to decrypt the plaintext message and print the result.
- Display the decrypted message.
Background: The Caesar Shift
The Caesar Shift cipher is a simple encryption technique based on substitution. In this example, a shift of three was chosen as the key. Each letter in a plaintext message is replaced by the letter three positions further down the alphabet. For example, with a Caesar Shift of three, the letter A in the original message is substituted with the letter D in the cipher message.
Public Domain
Can you decode the message shown?
FRPSXWHU VFLHQFH URFNV
The Caesar Shift does not seem very secure, but keep in mind that most of his adversaries were illiterate. As long as the generals could decode the messages, security was maintained. However, Caesar apparently had more sophisticated encryption techniques when dealing with his political enemies.
A cipher utilizes an algorithm and a key, which specify the exact details of how to encrypt a message. The Caesar Shift algorithm designates which letter in a cipher alphabet to substitute in the plaintext alphabet.
For example, if the consecutive letters of the alphabet (x) are represented by the integers 0-25 (e.g., a = 0, b = 1, z = 25), the encryption (En) or decryption (Dn) of a letter x by a shift n can be calculated as follows: En(x) = (x + n) En(x) = (x + n) - 26 Dn(x) = (x n) Dn(x) = (x n) + 26 if 0 x + n < 26 ifx + n 26 if 0 x - n < 26 ifx-n
Step by Step Solution
3.47 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started