Introduction to System Software - Programming Assignment 1 | CS 0449, Study Guides, Projects, Research of Computer Science

Material Type: Project; Class: INTRO TO SYSTEMS SOFTWARE; Subject: Computer Science; University: University of Pittsburgh; Term: Summer 2008;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 09/02/2009

koofers-user-ju2
koofers-user-ju2 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS0004: INTRODUCTION TO SYSTEM SOFWARE
PROGRAMMING ASSIGNMENT 1:
[XVIGENERE CIPHER]
Assigned: 05/28/2008
Due: 06/11/2008
Late Due Data (-15 pts): 06/13/2008
1 Preamble
In this project, you will implement an extended version of the vigenere cipher (‘Xtreme
vigenere or xvigenere). Besides the vigenere table substitution you will also add some rotation to the
bits in the characters to further obscure the text.
2 Introduction:
The Vigenere cipher is a method of encrypting alphabetic text by using a series of substitutions
based of a key. The cipher makes use of the classical Caesar Cipher that shifts each character in the plain
text (unencrypted file) by a certain number and wraps around if the shift amount goes beyond 26 (Z).
For instance, a Caesar cipher that uses a shift amount of 3 will turn A into D, B into E,…,X into A (wrap
around), Y into B and Z into C. Consider the word “ATTACK” shifted by 3 letters each. The result will be:
DWWDGN.
Notice that in this case all the letters are shifted by the same amount! The Vigenere cipher complicates
things just a little bit more, by shifting successive letters by different amounts. So basically, the Vigenere
cipher is a sequence of Caesar ciphers with different shift amounts.
The vigenere cipher makes use of a keyword and the Vigenere tableau (Vigenere table). The letters in
the keyword (key) are applied successively to the plaintext letters to create the cipher text (encrypted
file). To determine the shift amount for a particular letter in the plain text , use the keyword letter to
look up the corresponding cipher letter from the table. (Each letter in the key tells you how much to
shift the plaintext letter by, A is 0 B is 1 C is 3 etc.) The Viegenre tableau is shown in figure 1 below.
Take the plaintext, ATTACK and the key BOOK.
To encrypt the plaintext take each character in turn and apply the corresponding key letter (wrapping
around when the end of the key is reached).
A will use the key letter B to find its shift amount
pf3
pf4
pf5

Partial preview of the text

Download Introduction to System Software - Programming Assignment 1 | CS 0449 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CS0004: INTRODUCTION TO SYSTEM SOFWARE

PROGRAMMING ASSIGNMENT 1:

[XVIGENERE CIPHER]

Assigned: 05/28/

Due: 06/11/

Late Due Data (-15 pts): 06/13/

1 Preamble

In this project, you will implement an extended version of the vigenere cipher (‘Xtreme vigenere or xvigenere). Besides the vigenere table substitution you will also add some rotation to the bits in the characters to further obscure the text.

2 Introduction:

The Vigenere cipher is a method of encrypting alphabetic text by using a series of substitutions based of a key. The cipher makes use of the classical Caesar Cipher that shifts each character in the plain text (unencrypted file) by a certain number and wraps around if the shift amount goes beyond 26 (Z). For instance, a Caesar cipher that uses a shift amount of 3 will turn A into D, B into E,…,X into A (wrap around), Y into B and Z into C. Consider the word “ATTACK” shifted by 3 letters each. The result will be:

DWWDGN.

Notice that in this case all the letters are shifted by the same amount! The Vigenere cipher complicates things just a little bit more, by shifting successive letters by different amounts. So basically, the Vigenere cipher is a sequence of Caesar ciphers with different shift amounts.

The vigenere cipher makes use of a keyword and the Vigenere tableau (Vigenere table). The letters in the keyword (key) are applied successively to the plaintext letters to create the cipher text (encrypted file). To determine the shift amount for a particular letter in the plain text , use the keyword letter to look up the corresponding cipher letter from the table. (Each letter in the key tells you how much to shift the plaintext letter by, A is 0 B is 1 C is 3 etc.) The Viegenre tableau is shown in figure 1 below.

Take the plaintext, ATTACK and the key BOOK.

To encrypt the plaintext take each character in turn and apply the corresponding key letter (wrapping around when the end of the key is reached).

A will use the key letter B to find its shift amount

T will use O, and so on

Plain text: ATTACK

Key: BOOK BO

To find the cipher text, look up A under B in the table (basically row A column B, and the value there is B; Row T column O results in I, etc)

Cipher text: BIIKDY

Each letter is shifted by the amount [key_letter#-1] wrapped around when the end is reached (think modulo ‘%’)

Figure 1

3 PROJECT REQUIREMENTS

3.1 Key Generator (keygen)

In the first part of the project, you will create a small program that generates a random key of a specified length.

3.2.1 Options

3.2.1.1 – e If the option on the command line is – e then the program should encode using key in the key file as follows:

  1. Get the key length
  2. Get the rotation amount (rot)
  3. Get the key
  4. Encode each letter in the plaintext file (except spaces), C: a. Find the corresponding cipher letter from the tableau (call it Ck ) b. Rotate the cipher letter by the rotation amount (rot) - rotate(Ck,rot) to get Crot which becomes your final cipher
  5. Dump all the Crot in a cipher file called .enc; a. Eg, if the plain file was called plain1.txt, then the cipher file will be called plain1.enc.
  6. In all likelihood, the output file will be a binary file. To get the program to work properly use unsigned char instead of char to work with all your characters.

3.2.1.2 – d If the option is – d then the reverse of the previous operation is performed (a cipher text file is decoded). Decode as follows:

  1. Get the key length
  2. Get the rotation amount (rot)
  3. Get the key
  4. For each character in the cipher text file Crot: a. Reverse rotate it- rotate(Crot , -rot) to get Ck b. Use the key letter k and Ck to find the corresponding plaintext letter in the tableau.
  5. Write the output to a file called .txt a. E.g if the cipher file was called “cipher1.enc “, then the plaintext file will be “cipher1.txt.”

3.2.2 Plaintext files All plaintext files will contain letters of the English alphabet, spaces and punctuations. There will be no other characters. You have to encode everything (including spaces and punctuations). There will be notnumbers (digits) in the test plaintext files.

The letters will be a mixture of uppercase and lowercase letters.

The files could be of any length (don’t make any assumptions as to the number of lines or the number of letters on a line). Keep reading and processing the file until the end of file is reached (EOF).

3.2.3 Keys Each key will be no more than 256 letters long. The keys will be made up of ONLY letters of the English alphabet.

Use the pseudorandom generator function rand() in the standard library (stdlib.h)

3.2.4 Rotation The rotation amounts will range between -8 and 8. If the rotation amount is positive then you should rotate the bits of the character to the right else rotate to the left. After rotation, the cipher text letters are going to be unreadable (binary characters). You may want to use unsigned char instead of char. (you will have to cast the EOF to unsigned char (unsigned char)EOF)

NOTE: The decoded file should be the same as the original!

4 Other requirements

There are sample plaintext files with their corresponding ciphertext files on the assignment page [www.cs.pitt.edu/~anti/cs0449/projects]

4.1 Policy on cheating

All work must be your own. You can discuss the project with your colleagues to gain some insights. Bu the final project should be YOUR OWN. Any student or group of students found to have shared code will receive a zero on this assignment.

You are not allowed to cannibalize code from the internet. You can search for ideas, but plagiarizing code from the internet is punishable by a zero score!

If you have any questions, please do not hesitate to inform the TA or the instructor, we’ll be glad to assist you.

4.2 Submission Requirements

  1. All programs should be named as specified a. keygen.c for the key generator b. xvigenere.c for the encoder/decoder
  2. Make sure you comment your program. a. Add a README file that answers details out what you did and how, any errors or problems encountered, etc i. Add your name to the README file (this file should go into the project folder)
  3. Put all your programs in a folder/directory called Assignment
  4. Compress your project using the unix tar utility a. tar – xvf LastNameFirstname.tar Assignment b. Please adhere to this convention strictly, it is very very important!
  5. Submit the work to the submission directory CS449-anti/Assignment1 using anonymous ftp: a. Log in to ftp cs.pitt.edu

5 Hints

  1. Read the characters one character at a time (fgetc(FILE*)) a. For each character read, encode or decode it and write it out to the output file