DEVRY COMP 122 Lab 7 Lab Report and Source Code .pdf
Original filename: DEVRY COMP 122 Lab 7 Lab Report and Source Code.pdf
This PDF 1.5 document has been generated by Microsoft® Office Word 2007, and has been sent on pdf-archive.com on 28/02/2017 at 10:59, from IP address 43.224.x.x.
The current document download page has been viewed 85 times.
File size: 105 KB (3 pages).
Privacy: public file
Download original PDF file
DEVRY COMP 122 Lab 7 Lab Report and
Check this A+ tutorial guideline at
For more classes visit
COMP 122 Week 7 iLab
The focus of this lab is on using strings. You will have an opportunity to work with
both C style strings and the string data type. This lab also gives you an opportunity to
use what you have learned previously, including using functions, array processing,
repetition, and selection. You will also have an opportunity to work with file input
You are to design and implement a program which does encryption and decryption
of data from files. Encryption is the process of taking plain lines of text and
performing some algorithmic transformation on the data to create an encrypted line
of text which looks nothing like the original. Decryption is the process of taking an
encrypted line of text and performing some algorithmic transformation on the data
to recover the original line of plain text.
Encryption and Decryption Approach
Our approach to encryption and decryption involves two strings. The first is an
encryption / decryption string which we will allow to be up to 128 lower case
alphabetical characters in length. The second string is a line of text from a file that is
to be encrypted or decrypted.
Our basic strategy for encrypting data is based on mapping alphabetical characters
to specific values, then doing some simple mathematical operations to create a new
value. First of all, every character in either the encryption string or the input string is
mapped to a number between 0 and 25 based on its position in the alphabet.
The mapped value of a character is easily obtained by doing the following:
For lower case characters, subtract 'a' from the character.
For upper case characters, subtract 'A' from the character.
To calculate the modified value of the first character of input we add its mapped
value to the mapped value from the first character of the encryption string. This
modified value is then adjusted using % 26 to make sure that the final modified
value is within the 0 - 25 range. To create the final encrypted character value for the
first character, simply do the following:
For lower case characters, add 'a' to the modified value.
For upper case characters, add 'A' to the modified value.
This is done for each alphabetic character in the input string. Non-alphabetic
characters simply maintain their present value. If the input string is longer than the
encryption string, simply reuse mapped values from the encryption string. For
instance, if the encryption string has 10 characters (index values 0 - 9), when
processing the 11th input character (index 10), simply use the input character index
% length of encryption string (in this case 10 % 10 is 0) to select the value from the
encryption string to use for mapping.
The decryption process is basically the same as the encryption process. The only
difference is the value of the mapped character from the encryption string.
For lower case encryption, the mapped from encryption string - 'a'
For upper case encryption, the mapped from encryption string - 'A'
For lower case decryption, the mapped - (character from encryption string - 'a')
For upper case decryption, the mapped - (character from encryption string - 'A')
Your program must meet the following requirements:
1. You must ask the user if they want to perform an encryption or decryption
2. You must ask the user to enter the name of the file they want to encrypt or decrypt.
3. You must get an encryption key from the user which can be up to 128 characters.
The key must be all lower case alphabetic characters.
4. You must have a function which takes the encryption key and creates an
encryption map from it. For each character in the encryption key string, subtract the
lower case letter 'a' and store the result in the corresponding encryption map array.
5. You must have a function which takes the encryption key and creates a decryption
map from it. For each character in the encryption key string, subtract the lower case
letter 'a' from it. Then subtract that result from 26 and store the value in the
corresponding decryption map array.
6. You must have a function which will do the encryption or decryption
transformation. This function takes the following parameters:
A constant C string containing the line of text to be transformed.
A constant C character array which contains the encryption or decryption map.
An integer which contains the length of the encryption map.
A string reference (output) which will contain the encrypted or decrypted string
The core of the encryption / decryption algorithm is