Homework 1, Project Encryption

Short Description:

Write a program which will support a number of encryption algorithms.

This assignment is worth 100 points.

Goals

When you finish this homework, you should:

Formal Description

You have been hired by the Florin Ministry of Foreign Information to assist in maintaining communications with their agents in the field. Each day, the ministry prepares communications which they have received, or are preparing to transmit, in a single batch run. The commands for the daily run are inserted into the file Commands.dat, the format of which will be discussed below. Messages, both to be sent and those received are each entered into a separate file. The Ministry supports a number of different encoding, and has, over the years, developed a system for identifying the actions to take on a message. This system is summarized in the following table:
Code LetterMeaningAdditional Arguments
A Convert characters to numeric ascii value  
a Convert two digit pairs to character  
I Increase all digits by 1, no carry  
i Decrease all digits by 1, no carry  
o Reverse the order of the characters in each word  
O Reverse the order of characters in the entire message  
C Employ the caesar cipher Shift
S Employ the self encoding caesar cipher + for add, - for subtract
P Translate into pig-latin  
p Translate from pig-latin  
> Copy  
+ Merge Second Source
= Compare  
The file Commands.dat will be in the following format: Some examples:
FILE1 A FILE2   Read from FILE1, write to FILE2 converting all characters to ascii equivalent
FILE2 a FILE3  Read from FILE2, write to FILE3, converting all two digit numbers to ascii  equivalent.
CODE1 C message 3 Read from CODE1, write to message, shift all letters by 3
FILE2 + FINAL_MESSAGE message Copy FILE2 and message to FINAL_MESSAGE
= FILE1 FILE2  Compare FILE1 to FILE2

Algorithm Discussions:

Ascii to Character and Back
Convert each letter to the ascii equivalent. Convert two character pairs, if possible, from ascii to the character equivalent.

The Ministry has trained all employees to work in hexadecimal (hex), so all values will be stored in hex. The ministry also requires proper formatting, so all values will be exactly two characters long. If an error is encountered in a pair (ie character > 'f'),print out the pair without change. Encode white space, but do not encode new line characters. Upper case letters between A and F are valid.

Example (A):

Attack at dawn!
Becomes
41747461636b206174206461776e21
Example (a):
41747461636B206174206461776E21hk1
Becomes
Attack at dawn!hk1
Increment/Decrement Digits
Encode a message by incrementing or decrementing all digits in the message.

All valid hex digits should be incremented or decremented by one. Non-hex digit characters should be output without change. There is no carry or borrow in this encoding, so '9' becomes 'a', 'f' becomes '0' when incrementing, and '0' becomes 'f' when decrementing.

Example (I)

41747461636B206174206461776E21hk1
Becomes
52858572747c317285317572887f32hk2
Example (i)
b eby in dbmp is 0un!
Becomes
a day in camp is fun!
Reverse word character order.
Reverse the letter order within each word.

A word is defined by the characters surrounded by white space character.

Example:

Attack at dawn!
Becomes:
kcattA ta !nwad
Reverse message character order.
Reverse all characters in a message.

Example

Attack at dawn!
Becomes:
!nwad ta kcattA
Caesar Cipher.
A caesar cipher is found by shifting all letters in a message by a fixed amount. For a simple caesar cipher, all letters are shifted by a given key. Note valid keys are between -25 and 25. Larger keys should be adjusted into this range. Upper case letters should be preserved in this encoding.

Example: (C, 3)

Attack at dawn!
Becomes
Dwwdfn dw gdzq!
Self Encoding Caesar Cipher.
This cipher algorithm uses the message as the key. For a given message, the first letter is just output. The second letter is shifted by the distance of the first letter from a, the third letter is shifted by the distance of the second letter from a and so on. Non letters are not encrypted. Upper case letters should be preserved in this encoding.

When encrypting a self encoding ceaser cipher, compute the key based on the current letter. When decrypting a self encoding ceaser cipher, you should compute the key based upon the shift of the current letter.

Example: (C, 3)

Attack at dawn!
Becomes
Atmtcm kt wdwj!
Translate into Pig Latin
Translate each word into Pig Latin. To translate a word into pig latin.
  1. Locate the first vowel in the word (a,e,i,o,u). If there is not a vowel in the word, do not translate it.
  2. The word is now in the form prefixVpostfix, where prefix are the characters which proceed the first vowel (V) and postfix are the letters which follow V.
  3. Output the word Vpostfix-prefixay.

Example:

Attack at dawn!
Becomes: Attack-ay at-ay awn!-day
Translate into Pig Latin
Reverse the translation into pig latin. If a word is not in pig latin, output the work unchanged.

Discussion

Required Files

You should submit the following in a tar file: You should not submit

Submission

Please create a tar file containing the files described above. Email this file to danbennett360@gmail.com by class time of the due date.