Write up your answers in a file called lab3.txt
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.java
. This can capture straight, expansion
and compression boxes.
int size
stores the maximum size of input integers
int[] perm
stores the permutation
public PBox(int size, int[] perm)
is the constructor, and sets the size and
permutation.
public int permute(int num)
runs the input number num through the permutation.
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 {...
.
int[][] table
stores the table for lookup of the output numbers.
int bitmask
stores a number, where in binary representation, 1's mean the bit will
be used as part of the row lookup, and 0's mean the bit will be used as part of the
column lookup. The ordering of the bits will not change.
public SBoxTable(int[][] table, int bitmask)
is the constructor,
and sets the table and bitmask.
public int substitute(int num)
runs the input number num through the substitution.
Operator | Name | Example | Result | Description |
---|---|---|---|---|
a & b | and | 3 & 5 | 1 | 1 if both bits are 1. |
a | b | or | 3 | 5 | 7 | 1 if either bit is 1. |
a ^ b | xor | 3 ^ 5 | 6 | 1 if both bits are different. |
~a | not | ~3 | -4 | Inverts the bits. |
n << p | left shift | 3 << 2 | 12 | Shifts the bits of n left p positions. Zero bits are shifted into the low-order positions. |
n >> p | right shift | 5 >> 2 | 1 | Shifts 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 >>> p | right shift | -4 >>> 28 | 15 | (Only in Java) Shifts the bits of n right p positions. Zeros are shifted into the high-order positions. |
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