Threesuns

Email the Instructor

Contact

All Semesters

Semesters

All Courses

Courses

2017Summer

06.05.17 - 07.30.17

C Language

CSCI2473

Tuesday Thursday
09:30 AM - 12:20 PM

Substitution Cipher

Lab08

Objective: To practice with FileIO

pastdue

Submit Your Solution

Lab08

Request a Copy of your Solution

Lab08

Requirements

Program can correctly encrypt a clear text file30 pts
Program can correctly decrypt a crypt text file30 pts
Program uses a cipher from file20 pts
Program handles specified errors20 pts
Total100 pts

Instructions

Overview

According to Wikipedia "In cryptography, a substitution cipher is a method of encoding by which units of plaintext are replaced with ciphertext, according to a fixed system; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth."

For this lab you will write a C program that will be able to encrypt text files with a substitution cipher or decrypt text files that have previously been encrypted with a substitution cipher.

Execution

The user of this program should be able to execute the program from the command line and should be able to provide all of the information the program needs in the form and command line arguments and files. The basic form of the command the user should be able to execute is:

program_name <cipher_file> <encrypt|decrypt> <clear_text_input_file.txt | crypt_text_input_file.txt> <clear_text_output_file.txt | crypt_text_output_file.txt>

In this command:

  • program_name is the name of your executable program
  • cipher_file is a text file containing the substitution cipher
  • clear_text_input_file.txt is a file containing unencrypted text
  • crypt_text_input_file.txt is a file containing encrypted text
  • clear_text_output_file.txt is a file used to store clear text after it's been decrypted
  • crypt_text_output_file.txt is a file used to store crypt text after it's been encrypted

Examples of some commands:

a cipher.txt encrypt clear_text.txt crypt_text.txt

This command would run the program called 'a' using the cipher contained in the file cipher.txt to encrypt the content of the file called clear_text.txt and would store the encrypted output into crypt_text.txt

./a.out cipher.txt decrypt crypt_text.txt clear_text.txt

This command would run the program called 'a' using the cipher contained in the file cipher.txt to decrypt the content of the file called crypt_text.txt and would store the decrypted output into clear_text.txt

The Cipher

The cipher itself will be stored in a file where every letter of the alphabet is matched with a 'converted' letter it matches up with. If in your substitution cipher the letter A was changed into the letter X then the line:

A X

would appear in the cipher file with a space separating the two letters (space delimited). An example of a cipher file is attached at the bottom of the assignment.

Example Substitution

If the sample command above was executed:

a cipher.txt encrypt clear_text.txt crypt_text.txt

and the clear_text.txt file contained:

THIS IS A SAMPLE FILE
THAT HAS SOME SAMPLE TEXT
IN IT.

THIS IS SOME EXTRA

Then after the command was run the file called crypt_text.txt would contain:

URFK FK Q KQYBAO SFAO
URQU RQK KXYO KQYBAO UOGU
FL FU.

URFK FK KXYO OGUMQ

Errors

The program should gracefully handle the following issues:

  • wrong number of command line arguments given
  • incorrectly formed cipher file
  • missing instruction to encrypt or decrypt
  • input file can not be opened

Extras