CPSC 430 Programming Assignment
SDES in Cipher Block Chaining Mode
Due Friday, March 18, 2011
Write a program in either Java or C++ that
implements encryption and decryption using the SDES algorithm
in CBC (Cipher Block Chaining) mode.
Your program must meet the following requirements:
- It must have an SDES class. The SDES class will
work with integers only - no strings
or other data types should be used anywhere in the class. The size of
integer is optional (int, short, etc). The class
must have the following:
- Static or Constant Class Members: The permutation arrays.
These should be arrays of integers that can be set up using
a declaration/initialization statement. Ideally the sbox
matrices (tables) are here also but those of you who have them encoded in
a method/function may leave them that way (no strings or other
data structures, however).
- Instance data/Member data: the two subkeys (integers).
- A constructor that takes an integer parameter representing
the key. The constructor should set up the subkeys.
- Public methods to encrypt and decrypt. These
take one integer parameter, representing the
8-bit plaintext or ciphertext as appropriate.
Each method should return an integer for the ciphertext (or
- The class must use bitwise operations for
all internal calculations (permutations, xor); there should
be no going back and forth between integers and more complex
- There should
be ONE generic method/function to perform a permutation on the
bits in an int.
- Private helper functions as needed to perform steps
in the SDES algorithm.
- A CBC mode class that performs encryption and decryption
using SDES in CBC mode.
- Member/Instance Data: Two integers representing the
SDES key (the full 10-bit key, not the subkeys - the SDES class
is responsible for computing those)and the Initial Value (the
integer value of the 8-bit initial value);
an SDES object to perform the encryption and decryption,
an error flag for invalid key or initial value.
- A Constructor that takes two string parameters - one
for the key (10-bits) and one for the Initial Value (8-bits).
Appropriate methods in the class described below should be
called to validate (make sure 0s and 1s) and convert these to integers.
The error flag should be set if either the key or initial
value are invalid.
An SDES object should be instantiated.
- A method/function to encrypt text. This function should
take a string of 0s and 1s as a parameter and return a string
of ciphertext or an error message. The plaintext
should be "prepared" as appropriate for the CBC mode, then
the text should be encrypted (calling the SDES object
to encrypt each block according to the CBC protocol) if
there are no errors (bad key or iv or input).
The input string should be processed from left to right
and any padding of 0s should be on the right.
A string of ciphertext blocks
or an "encryption failed" message should be returned.
The string of ciphertext should have blank spaces
between the 8-bit blocks for ease of reading.
- A method/function to decrypt text. This is similar to encrypt
in that it takes a string of 0s and 1s as a parameter and returns
a string of plaintext or an error message.
- A class to handle conversion between strings and integers.
It should be responsible for making sure strings are strings of
0s and 1s.
- A test program that takes as input the SDES 10-bit
key, the 8-bit Initial Value, a character for the mode ('e' for
encrypt and 'd' for decrypt), and an arbitrary length string
of 0s and 1s for the plaintext or ciphertext. The program
should use a CBC mode object to encrypt or decrypt based on user
input. The result should be printed.
The input may be from a file (one file, not multiple files)
or command line BUT it must be in the following order:
- 10-bit key (in the form of a string of 0s and 1s)
- 8-bit initial value (in the form of a string of 0s and 1s)
- Character 'e' or 'd' to indicate encrypt or decrypt
- Arbitrary length string of 0s and 1s to encrypt or decrypt
- Document your program according to
- Tar or zip (no rar files)
the directory with your program and send the
file in as an email attachment.