Caeser Cipher and Matlab
HW 4/caesarDecode.m
function p = caesarDecode(c,key) % function p = caesarDecode(c,key) % % Caesar cipher decoding function. Input must be lower case. % % Example: % p = caesarDecode('khoor zruog',3); %
HW 4/caesarEncode.m
function c = caesarEncode(p,key) % function c = caesarEncode(p,key) % % Caesar cipher encoding function. Input must be upper case. % % Example: % c = caesarEncode('HELLO WORLD',3); %
HW 4/HW_4_Instructions-.pdf
The Caesar Cipher
Objectives
The objective of this homework is for you to learn about the Caesar cipher. You will first implement the Caesar cipher in Matlab (i.e., the decode and encode functions). Then you will implement a Matlab function that will implement two key based cipher generation. Additionally, a sub-objective is to gain further experience with the Matlab simulation environment.
Files
All the files (i.e., cover page, VHDL template files, reading material, etc.) are contained in a folder called “HW 4” which is available for download on TITANium. You must download these files prior to completing the following tasks.
Background
In cryptography, a Caesar cipher, also known as Caesar’s cipher, the shift cipher, Caesar’s code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a right shift of 3, “A” would be replaced by “D”, “B” would become “E”, and so on (see Figure 1). The method is named after Julius Caesar, who used it in his private correspondence.
Figure 1: The action of the Caesar cipher.
The encryption step performed by a Caesar cipher is often incorporated as part of more complex schemes, such as the Vigenère cipher, and still has modern application in the ROT13
system. As with all single alphabet substitution ciphers, the Caesar cipher is easily broken and in modern practice offers essentially no communication security.
Description
For this HW, you will complete three Matlab functions (i.e., “caesarDecode.m”, and “caesarEncode.m”). I created templates for these functions and they are available to you in the “Template Code” folder which is posted on TITANium.
Caesar Encode and Decode Functions
In the encode (“caesarEncode.m”) and decode (“caesarDecode.m”) functions, you are to create the Caesar cipher as discussed in the “Introduction to Cryptography” lecture. These functions will take in a string and a numeric key which indicates the shift. The encode function will take a string in all uppercase letters and the decode will take a string in all lowercase letters.
1/3
You are to loop through the string and, using the key, either encode or decode the string. If you code the functions correctly, they should work as shown in Figure 2. One thing to note, you must skip any white space (e.g., skip the space between “HELLO” and “WORLD” in the “HELLO WORLD” string). Some Matlab commands that might help you complete these functions are “find”, “mod”, “upper”, and “lower”.
Figure 2: Example output of the Caesar cipher encode and decode functions.
2-Key Substitution Function
Using the 2-key substitution function create an encode (“TwokeyEncode.m”) and decode (‘TwokeyDecode.m”) using the table shown in Figure 3. These functions will take in a string and use the key which is shown in Figure 3. The encode function will take a string in all uppercase letters and the decode will take a string in all lowercase letters. You are to loop through the string and, using the key, either encode or decode the string.
2/3
Figure 3 2-Key based on the Caesar cipher
What to Turn In (Please read this carefully)
For this HW, you only need to provide the Matlab code and the answers for the “Work Task” section. You must put the complete Matlab functions and the answers into a single PDF file. Your code must be in text format. Code provided as an image will not be accepted. You must label everything appropriately (i.e., label the code and work task sections). If I can’t understand your answers or code, I will assume it is incorrect. Also, please include the cover page in your Word doc. I will not accept any other file formats such as Matlab m-files, PDF, etc. This HW will be a digital submission and it will be submitted online using TITANium. No paper submissions will be accepted.
3/3
HW 4/TwokeyDecode.m
function p = TwokeyDecode(c,key1,key2) % function p = caesarDecode(c,key) % % Caesar cipher decoding function. Input must be lower case. % % Example: % p = TwokeyDecode('khoor zruog',key_1, key_2); %
HW 4/TwokeyEncode.m
function c = TwokeyEncode(p,key1, key2) % function c = caesarEncode(p,key) % % Caesar cipher encoding function. Input must be upper case. % % Example: % c = TwokeyEncode('HELLO WORLD',key_1, key_2); %