CS549: Cryptography and Network Security

Programming Projects

For this semester, you will do the programming project yourself, NOT as a group.

  1. For students at India (a special session for cs549), you will do the programming assignment INDIVIDUALLY also.

  2. The programming assignment are due by Dec 5th, 2010. You have to upload your code to blackboard AND demo your code to TA by making an appointment with TA before same due date. For students from India session, since you cannot do the demo directly to TA, you have to upload the detailed readme file to the blackboard such that TA can execute your code and test it. Thus, you need to have a commonly used operating system environment.

  3. Each student has to do BOTH programming assignments discussed in detail below.

Programming 1:

In this exercise you will build a simple cryptography program in a programming language of your choice. Then you will generate a few ciphertexts. Finally you will try to crypt-analyze other groups of ciphertexts.

For simplicity, we assume that the input alphabet is {a-z, A-Z, 0-9} plus a special empty space character. Your program shall perform the following functions:

1

From a plaintext produce an alphabetic substitution cipher. In other words, your key is a substitution rule for each possible input character. Here the key should be specified by a table of size 62 (since the alphabet size is 62). The first letter should define the substitution of letter 'a', the second letter defines the substitution of letter 'b', ...., the 26th letter defines the substitution for letter 'z', the 27th letter defines the substitution for letter 'A', and so on. For example, table [0123456789ABCDEFGHI....XYZabcdedg....xyz] defines a key, where letter 'a' will be replaced by '0', while '9' in the plaintext will be replaced by 'z'.

2

From a plaintext produce a transposition cipher. For uniform encryption by all students, we assume that the cipher will work on a block of 8 characters. In other words, you always permute within a block of 8 characters. If the input size cannot be divided by 8, you use blank to fill the rest of input to make it divisable by 8. Then for such encryption method, the key is specified by a permutation within {1,2,3,4,5,6,7,8}. Assume that you use key [2,3,4,5,6,7,8,1] (means you put the 2nd positioned letter to 1st position...). Then the encryption of plaintext "transposition cipher" will be as follows: first convert it to "transposition cipher " (with 4 blank spaces at end), then compute the encryption as "stranspoiition c pher " (with three blank spaces at end)

3

From a plaintext produce a product cipher based on the previous functions. For simplicity, assume that the substitution cipher is used first and then the transposition cipher is used to encrypt the result to get the final ciphertext.

 

 

Generate one cipher-method with each of the three functions (three cithers in total). For each cipher method (with a fixed key) you encrypt some arbitrary plain-text that contains the words "computer" and "security" inside the plaintext. Each text should contain at least 1000 characters and be of normal type (i.e. not medical).

 

 

After you produced the ciphertexts using each of the 3 encryption methods (with different keys), you now start to design methods to find the original plaintext using the given ciphertext. Begin with the simplest (1) and continue with (2) and (3).

1

Build your own tools or use ready-made tools or scripts to cryptanalyze the ciphers.

2

Try to get the plaintext from the ciphertexts.

3

Try to get the key or alphabet used.

What you have to submit for this part of the programming? You need to submit the following code and document:

  1. your code for producing ciphertexts using the above three methods, where the input of your code is a text-file (served as plaintext) and another text-file (that will specify the key for encryption). The output is a file storing the ciphertext.
  2. your code for producing plaintexts using the above three methods, where the input of your code is a text-file (served as ciphertext) and another text-file (that will specify the key for decryption). The output is a file storing the plaintext you decrypted. Here the key is the substitution or permutation used to shuffle the input letters or digits.
  3. your code for breaking the ciphers for each encryption method. The input of your code will have one file that is the ciphertext, and possibly another file that contains the list of words that will appear in the plaintext. The output of your code will be the plaintext and the key (stored in two separate text files).

Programming 2:

In this exercise, you will have to implement RSA encryption. You cannot use existing RSA implementations found from web or in JAVA. What you can use are

  1. Java has a built-in BIGINT class to store big integers you needed for RSA (such as finding large prime numbers)

  2. For C++ you can use a library such as NTL (Library for doing Number Theory) or GMP (the GNU Multiple Precision Arithmetic Library).

In other words, you can use these big-integer implementation to manage your data and do module operation, but not use the existing implemented methods (gcd, power, finding prime numbers, and so on). You have to implement these functions yourself. You can use existing secure function to produce large random numbers (some functions provided for random numbers cannot be used due to its weak security). Notice that JAVA provide tools to get random numbers in

java.util.random  or  java.security.SecureRandom

Similarly, C++ have rand() and srand() to generate random numbers. You can use the random number function provided by Java if implementing random numbers is really difficult for you. However, these methods there are not secure since Linear congruent method is the default method set for Java's two built in random number generators. So to enhance security, you are strongly recommended to implement your own good random number generator.

In your own RSA implementation, assume that the large prime numbers are at least 500 bits (but could be much larger than this).  you should write several functions yourself

  1. a function to find large prime numbers, when given number of bits as an input

  2. a function to compute gcd when given two large integers

  3. a function to produce a random encryption key when given the two large prime numbers used for RSA

  4. a function to compute the decryption key when given the encryption key e and the two large prime numbers p and q

  5. a function for encryption when given the message and encryption key e and the modulo n

  6. a  function for decryption when given the ciphertext and decryption key d and the modulo n

 

What you have to submit:

  1. a code that can encrypt a file using RSA, where the input of your code are two files: one file is the plaintext file and another file stores the key for encryption.

  2. a code that can decrypt a file using RSA, where the input of your code are two files: one file is the ciphertext file and another file stores the key for decryption.