This assignment is worth 40 points.
Your program should open the files codes.dat which will contain a series of messages, along with instructions on how to transform these message.
The format of the file is as follows
The possible codes are
encode shift 23 1 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG decode shift 23 1 QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD encode combine LEMON 1 ATTACK AT DAWN decode combine LEMON 1 LXFOPV EF RNHR encode altCombine ALBERTA 2 CALGARY Attack At Dawn decode altCombine ALBERTA 2 CPMCRYY Aiuwtr At OzawIn the following descriptions
To decode, the offset is subtracted from the ciphertext to produce a plaintext. Again non-alphabetic characters are removed.
When adding or subtracting an offset from a letter, the result should be returned to the alphabetic range. For example 'z'+ 1 become 'a', and 'A'-2 becomes 'Y'.
Shifting "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" by 23 will result in the ciphertext of "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD"
Decoding, or shifting "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD" by an offset of -23 will return the original plaintext of "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG".
Plaintext Letter | T | H | E | Q | U | |
---|---|---|---|---|---|---|
Shift Amount | 23 | 23 | 23 | none, whitespace | 23 | 23 |
Shift Calculation | "T" + 23 | "H" + 23 | "E" + 23 | none, whitespace | "Q" + 23 | "U" + 23 |
Ciphertext Letter | Q | E | B | N | R |
This offset is the distance from 'a' or 'A'. So the letter 'a' represents an offset of 0, while the letter 'C' is two characters from 'A', so it represents an offset of 2.
Please note that the key may contain non alphabetic characters including whitespace. Only alphabetic characters should be used when encoding and decoding. The key is guaranteed to have at least on alphabetic character.
Encoding "ATTACK AT DAWN" with the keyword "LEMON" produces the ciphertext "LXFOPV EF RNHR"
Decoding "LXFOPV EF RNHR" with the keyword "LEMON" produces the ciphertext "ATACK AT DAWN"
Plaintext Letter | A | T | T | A | C | K |
---|---|---|---|---|---|---|
Corresponding Key | L | E | M | O | N | L |
Shift Amount | 11 | 4 | 12 | 14 | 13 | 11 |
Shift Calculation | A+11 | T+4 | T+12 | A+14 | C+13 | K+11 |
Ciphertext Letter | L | X | F | O | P | V |
Note, when encoding ATTACK AT DAWN with LEMON, the key will need to used over.
ATTACK AT DAWN LEMONL EM ONLE
Encoding "CALGARY" with "ALBERTA" produces "CPMCRYY"
Decoding "CPMCRYY" with "ALBERTA" produces "CALGARY"
Plaintext Letter | C | A | L | G | A | R |
---|---|---|---|---|---|---|
Corresponding Key | A | L | B | E | R | T |
Shift Amount | 0 | 11 | 1 | 4 | 17 | 19 |
Key position | 0 (+) | 1 (-) | 2 (+) | 3 | 4 | 5 |
Shift Calculation | C+0 | A-11 | L+1 | G-4 | A+17 | R-19 |
Ciphertext Letter | C | P | M | C | R | Y |
codetype n lines whith ciphername.
Where:
The following is an example of the output when the program is run
$ hw4 Encoding 1 lines with shift. QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD Decoding 1 lines with shift. THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG Encoding 1 lines with combine. LXFOPV EF RNHR Decoding 1 lines with combine. ATTACK AT DAWN Encoding 2 lines with altCombine. CPMCRYYAiuwtr At OzawAiuwtr At Sbse Decoding 2 lines with altCombine. CALGARY Attack At Dawn
while (value < 0) { value += 15; }
-g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -std=c++17
To create tar file, follow the Working with the Tape Archive Utility (tar)