CSC350 - Lab 3
Modern Ciphers - Simple DES


Part 1 - GF(2n)

  1. Add the following numbers from GF(32). Record your number in binary.
    1. 01001 (+) 10011
    2. 10111 (+) 10111

  2. Multiply the following numbers from GC(32) using x5 + x2 + 1 as the irreducible polynomial. Show your work using the multiplication algorithm on page 113. Record your number in binary.
    1. 0101 (*) 1001
    2. 1011 (*) 1011

Write up your answers in a file called lab3.txt

Part 2 - Simple DES

In this project, you will implement a simplified version of the DES block cipher algorithm, called SDES, and it is designed to have the features of the DES algorithm but scaled down so it is more tractable to understand. (Note however, that SDES is in no way secure and should not be used for serious cryptographic applications.)

This algorithm is discussed in detail in Appendix O of the textbook. Your input will be a String representing in binary an 8 bit integer, and String representing in binary a 10 bit key, and your output will be a String representing the encrypted bits.

You must write the following classes (described here in Java, but you are welcome to implement them in Python). You may write whatever additional classes you feel necessary to complete the project (such as a round key generator class, or a mixer class).

PBox Class

The first class you will implement is PBox.java. This can capture straight, expansion and compression boxes.

Data Members

Methods

You can add a main method to this class for unit testing, and should, but it is not necessary.

SBoxTable Class

You will also implement SBoxTable.java. This is an implementation of an SBox interface where the output value is found through table lookup. Your class declaration must be public class SBoxTable implements SBox {....

Data Members

Methods

You can add a main method to this class for unit testing, and should, but it is not necessary.

SDES class

This class will implement the SDES encryption cipher. It should hold the initial and final permutation PBoxes, the PBoxes in the key generator, the PBoxes and SBoxes for the mixer, and a function to perform repeated rounds and swap the bits in between rounds.

The bitwise operators

You must use bitwise operators in Java or Python in this assignment.

OperatorNameExampleResultDescription
a & band3 & 511 if both bits are 1.
a | bor 3 | 5 71 if either bit is 1.
a ^ bxor 3 ^ 5 61 if both bits are different.
~anot ~3 -4Inverts the bits.
n << pleft shift3 << 212Shifts the bits of n left p positions. Zero bits are shifted into the low-order positions.
n >> pright shift5 >> 21Shifts the bits of n right p positions. If n is a 2's complement signed number, the sign bit is shifted into the high-order positions.
n >>> pright shift-4 >>> 28 15(Only in Java) Shifts the bits of n right p positions. Zeros are shifted into the high-order positions.

Test Cases

You can generate test cases and intermediate tests with the SDES Calculator.

You may not download the code from this site or any other, you must code this from the algorithm description in Appendix O.

To verify that your implementation of SDES is correct, try the following test cases:

 Raw Key    Plaintext Ciphertext 
0000000000  10101010   00010001 
1110001110  10101010   11001010 
1110001110  01010101   01110000 
1111111111  10101010   00000100 

Use your implementation to complete the following table:

 Raw Key    Plaintext Ciphertext 
0000000000  00000000      ? 
1111111111  11111111      ? 
0000011111  00000000      ? 
0000011111  11111111      ? 
1000101110     ?       00011100 
1000101110     ?       11000010 
0010011111     ?       10011101 
0010011111     ?       10010000 

Write the results of your table in lab3.txt

What to turn in

  1. PBox.java, SBox.java and SDES.java or
  2. SDES.py and
  3. lab3.txt