CIS071 Lab 13 - Cryptography
DUE: (Monday May 8, at NOON – firm deadline)
Scope: String character functions, String input, FileIO
Lab
13: Cryptogram Encoder. Cryptography is used to
protect messages from unauthorized viewers.
An algorithm using an encoding key scrambles the letters in a message
string, making it unintelligible to anyone not having the key.
A
simple encoding algorithm involves substituting one lower case letter for
another, e.g. replace each letter in the range a to z with
a different letter in this range. To
insure proper decoding, each letter should be used exactly once. A 26 character string is used to define this
substitution. The positions in the
string correspond to the alphabet order.
The character at each position of the string is the value to be
substituted. Note that all other
characters (upper case characters, punctuation, whitespace
etc) are unchanged. Also note that the
same program can be used for both encoding and decoding a message. The only thing that changes is the conversion
string.
Assignment.
Write a program encode.c
that encodes the original text file into encrypted text.
Write a program decode.c
that decodes the encrypted file into its original form.
You should allow user to choose the source and
destination file names, and also to provide the name of text file that contains
the encoding key string of length 26.
Details:
To
encode or decode a file you should
1. Define a 26 character
conversion string (as described above) to encode the message. Place this string in file encodekey.txt
2. Write a function that
converts the conversion string from encodekey.txt into its complement
that allows a text file to be decoded.. This function should be a part of the decode.c
program.
3. Create an input message file
cryptoin.txt containing several lines of text with upper/lower case
letters, numbers, punctuation, spaces etc all intermixed. The message should be readable.
4. Write program encode.c that
uses the string from encodekey.txt
to convert the source file (e.g. cryptoin.txt) to encrypted output file (e.g. cryptoout.txt). You should do the similar with decode.c program.
Example:
convert = cdefghirslmnopqjktuvwxyzab
cryptoin.txt = Now is the time for all 99 men
cryptoout.txt = Nqy su vrg vsog
hqt cnn 99 ogp
cryptoback.txt = Now is the time for all 99 men