# 1 Experiment

** **

The aim of this project is to develop a Feistel Cipher and understand the internals of Feistel ciphers e.g. DES, IDEA, RC4/5. You will learn multi round ciphers that enable to encrypt/decrypt data with the right key. You will also learn to implement ECB, CBC and OFB encryption modes for your Feistel Cipher.

A Feistel Cipher has the below format as discussed in the class:

A Feistel Cipher has *d* rounds of encryption, where in *i ^{th}* round, a one-way scramble function

*f*is applied to right half of the data

*R*with subkey

_{i}*K*.

_{i}In this project, the main parameters of your Feistel Cipher will be as follows:

- 10 rounds of encryption/decryption
- 96 bit block size
- 96 bit key size

__If the length of the message is less than the block size, the message will padded with all__ __zeros to obtain a 96 bit block.__

**Scramble Function: **

In our project, we will assume that scramble functions *f _{0}, f_{1}, f_{2} … f_{d-1}* applied on each round are

__all same__. In other words, you will have only one scramble function, which is defined as follows

In the above scramble function, *R _{i}* is XORed with

*K*first and the result is divided into 8 pieces of 6-bit parts (

_{i}*P1, P2, P3, … P8*). Then, P1 and P2 are XORed and saved as the 9

^{th}part, P3 and P4 are XORed and saved as the 10

^{th}part and so on. As a result of these operations, you will have 12 pieces of 6-bit parts. Then, each 6-bit part is sent to a substitution box like in the DES algorithm. You are expected to use below substitution box:

The substitution box works in similar way to DES boxes. Outer bits of the input are used as the row number, inner bits are used as the column number. The results of 12 substitution box operations will be combined as a 48 bit output and a permutation function will be applied on this output. The permutation function swaps each even digit with the previous odd digit. Assuming *B _{i}* represents i

^{th}bit of the output, the permutation function will do following operation for all bits of the result (0≤ ≤47): Temp = B

_{2i}

B2i = B2i+1 B_{2i+1} = Temp **Subkey Generation: **

In each round, you will do apply a left circular shift on the key and a permuted choice on the key as shown in below figure:

In the even numbered rounds, the permuted choice will output even digits of the key to the related round. In other words, in rounds 0, 2, 4, 6, and 8, the permuted choice function will output 0, 2, 4, 6, 8, …. 94^{th} bits, which is 48 bits in total. In the other (1,3,5,7,9) rounds, the permuted choice function will output odd digits, which are 1, 3, 5, 7, 9, …. 95^{th} bits.

**Encryption modes: **

You will implement ECB, CBC, and OFB modes for your encryption algorithm. In case, if CBC or OFB modes are selected, your program should use a vector filled with 1s as the Initialization Vector.

# 2 Usage and testing

__Your program____ must be named as “BBMcrypt”__ and should run from the command line with the following parameter format:

BBMcrypt enc|dec -K key -I input -O output –M mode

*enc|dec*specifies the action, which can be either encryption or decryption- –
*K key*specifies the file name that contains encryption/decryption key, which is encoded in base64 encoding *-I input*specifies the input file name, which can be either plaintext or ciphertext*-O output*specifies the output file name, which can be either plaintext or ciphertext*-M mode*specifies the encryption mode, which can be ECB, CBC or OFB.

* *

Your program will be tested on different sized files using the above command line format. __Thus, it is important to obey this command line format or otherwise, you will lose__ __points.__

We will not test wrong parameters of users, such as missing input file name, key file name. However, -K, -I, -O, and -M parameters might be given in different orders on the command line (The first parameter must be always *enc|dec*).

# 3 Notes

- You can ask questions about the experiment via Piazza group:

piazza.com/hacettepe.edu.tr/fall2020/bbm465

- Late submission will not be accepted!
- You must compile and run your program on Ubuntu operating system before submission.
- You are going to submit your experiment to online submission system:

www.submit.cs.hacettepe.edu.tr

The submission format is given below:

<Group id>.zip

−java/

−−*.java

## Reviews

There are no reviews yet.