Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Caesar Cipher Homework: Encoding and Decoding Messages in C++, Assignments of Cryptography and System Security

Instructions for a homework assignment in the introduction to programming course at ucla math department during summer 2009. Students are required to write a c++ program that implements caesar cipher encryption and decryption. The program should take a key and an encrypted message as inputs and print the decoded message in all caps with each word separated by a space. Students are also asked to explain their design decisions and submit a readme file with comments on the project. Sample ciphertexts and grading criteria.

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-hfd-1
koofers-user-hfd-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Caesar Cipher Homework: Encoding and Decoding Messages in C++ and more Assignments Cryptography and System Security in PDF only on Docsity! PIC 10A: Introduction to Programming UCLA Math Department Summer 2009 Homework 4– Secret Message Due Tuesday, July 21, 2009 4:00 PM Sharp Paranoid of government spying, you have decided to communicate with your friends in the form of encoded messages. Unfortunately, you daydreamed your way through your cryptography class and you can only remember a simple encryption technique, known as Caesar’s cipher. This cipher works by replacing each letter in the text by another letter some fixed number of positions down the alphabet. For example, if the key is three. The letter A becomes D, the letter B becomes E, and so on. There are a couple of useful ways of looking at this transformation. The first is by aligning two alphabets. The cipher alphabet is rotated to the left (here the key is three): Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ Cipher: DEFGHIJKLMNOPQRSTUVWXYZABC Another way of look at the cipher is by assigning each letter a sequential number (A=0, B=1, C=2, ... ). If a letter if represented by the number, n, we can find the encoded letter, e, by the formula e = (n + k) mod 26, where k is the key. Similarly, we can decrypt the encoded letter, e, with the formula n = (e− k) mod 26, Here, mod means if n + k (or e− k) is not in between 0 and 25 subtract (or add) 26 until it is. Using the key, 3, we see that: plaintext: HELLO WORLD ciphertext: KHOOR ZRUOG Tired of decoding messages by hand you decide to write a C++ program to do it for you. Write a program that prompts for a key and an encrypted message and then prints out the plaintext. The key is a positive integer between 1 and 25. The encrypted message will contain only upper and lowercase letters and whitespace. In particular, the ciphertext may appear on multiple lines. The encrypted message will be terminated with CTRL-D (CTRL-Z on Windows). You will then print out the decoded message in all caps with each word separated by a space. (For help with making every letter uppercase try the function toupper() declared in cctype. A short description may be found in the appendix of your textbook.) In order to receive full credit your program must define at least one function that passes a parameter by const reference, and at least one function that passes a parameter by reference. Try decoding the following messages: key=14, ciphertext="W OA BCH GZOQYWBU CTT AM QCRS WG QCADWZWBU" key=7, ciphertext="AV LYY PZ OBTHU IBA AV YLHSSF MVBS AOPUNZ BW FVB ULLK H JVTWBALY"
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved