University of Calgary

encryption - reversal

ENCRYPTION (Reversal)
source: Katrin Becker, 2001
CONTENTS of THIS PAGE...
Goals, Skills & Concepts, Introduction & Background, Description
Specifications, Approach, Minimal Requirements
('C' version), ('B' version), ('A' Version)
Testing and Marking
Bonuses, Challenge
Goals, Skills and Concepts:
- Use of Command-Line Arguments
- The nature of ASCII characters (and their manipulation)
- Character Manipulation
- Use of utilities (i.e. UNIX od and diff) in program testing and development
- Intro to Encryption
- Intro to Binary Files
Introduction and Background:
Encryption: <algorithm, cryptography> Any procedure used in cryptography to convert plaintext into ciphertext in order to prevent any but the intended recipient from reading that data. There are many types of data encryption, and they are the basis of network security. Common types include Data Encryption Standard and public-key encryption.

The Unix command crypt performs encryption.
http://eff.org/
This is a very large and complex area of study, both in Computer Science and Mathematics and cannot be dealt with (except superficially) in this context. Our goal in this assignment will be to implement a very simplstic encryption algorithm. Given it's simplicity, it is one that would be quite eaasy to "crack" .
Don't use this to encrypt sensitive material ;->. Any algorithm that does exactly the same thing to each character will be easy to decipher because all occurences of the same original character will still have the same bit pattern as each other in the encrypted message.
Explanation:
Let's say we have an encrypted message. We suspect it is an English text message. We know many things about English text: such as that the most common letter in the english language is 'E'. So what we could do is count the frequencies of the bytes in the encoded message, look at the most common byte, see what needs to be done to it to turn it into an 'E', and then try that with all the bytes. This is all it would take to crack our program.
Description:
The algorithm we will implement does character by character encryption (a common approach) but all we will do is reverse the ASCII codes for each character we encounter.
NOTE: encrypted text will probably not be readable as text. In order to view the output in the file you must use the UNIX facility od (octal dump). ATTEMPTS TO DISPLAY THE OUTPUT FILE AT THE SCREEN MAY MESS UP YOUR SCREEN OR WORSE!!! ALSO: DO NOT ATTEMPT TO PRINT THE OUTPUT FILE (same reasons, plus it will annoy UCS and may result in many pages being printed which you may have to pay for).
Specifications:
-MUST do file I/O
- MUST use command line arguments
Approach:
This is a smallish program, requiring no new material except command-line args.
 
Requirements & Grading:
Both encode and decode must be accomplished by the same program, in other words, running the output file through the program again should result in the original input back.
'C' Version:
- handles file I/O correctly
- converts characters correctly
- echoes characters ('raw' and encoded)
'B' Version:
- allows an optional echo (i.e. implements {-d} option)
'A' Version:
- allows encryption in place (input and output files are one and the same)
- allows input from the screen (standard input) as well as from file
- not in the same run
- output always to file
 
Testing:
There are two sample executable versions in the course directory:
      /home/233/Encryption/reverse { the 'C' version }
      /home/233/Encryption/reverse2 { the 'A' version }
       
Test your program using at least the following files :
1. /home/233/Encryption/cheese.txt
2. /home/233/Encryption/lies.txt
3. /home/233/Encryption/needs.txt
4. your original source program (do not display this one; encode it, then decode to a new file and compare the original against the 2nd target file using diff)
 
BONUSES:
1. Allow additional encryption which does a bit reversal on bytes -r N
where N = # of bits to reverse
(0 = no encryption;
1 = switch every pair of bits;
2 = switch 2 bits in every 4;
4 = same as original assingment;
range of N 0,1,2,4)
2.Allow a different , alternate encryption which does a circular shift on bytes (-s N )
where N = # of bits to shift
(0 = no encryption;
7 = all bits;
range of N 0-7)
Challenges:
Not this time. On some assingments, the most involved and challenging bonuses (OK, sometimes just stupidly hard or rediculous amounts of work) will be listed under this category.



Updated: August 29, 2005 12:12 PM