University of Calgary

cyclic encryption

Simple Cyclic Encryption 
source: Katrin Becker 1999
Write an encryption program that reads from cin and writes to a specified file using this simple encryption scheme:
- the encrypted form of a character c is c^key[i] (^ is the XOR operator) where key is a string passed as a command-line argument
 
The program uses the characters in key in a cyclic manner until all the input has been read.
 
Re-encrypting encoded text with the same key produces the original text.
 
If no key (or a null string) is passed, then no encryption is done.
 
NOTE: encrypted text will probably not be readable as text. In order to view the output in the file you must use the UNIX facility od (octal dump). ATTEMPTS TO DISPLAY THE OUTPUT FILE AT THE SCREEN MAY MESS UP YOUR SCREEN OR WORSE!!! ALSO: DO NOT ATTEMPT TO PRINT THE OUTPUT FILE (same reasons, plus it will annoy UCS and may result in many pages being printed which you may have to pay for).
 
Testing:
Test your program using at least the following:
source strings to encode:
1. There's no cheese Gromit!
2. The needs of the many outweigh the needs of the few, or the one.
3. All lies lead to the truth.
key strings to use for encryption (note: keys containing embedded blanks must be enclosed in quotes):
1. Fight the Future
2. Cracking toast, Gromit
3. ' ' (i.e. a single blank - must be in quotes)
 
Run at least 2 of them through the encoder twice to prove the re-encryption works.
 
BONUSES:
1. do Input using files; allow user to choose output file name
2. allow the option of generating a random string to be used as the encryption string (this string must be given to the user for de-cryption)
3. allow > 1 line of input (will need an end-of-input marker)
4. allow the option of generating an actual 1-Time Pad (generate the pad as the text is processed). Program must still encode in the original way as well.



Updated: August 29, 2005 01:07 PM