CS3750 Homework2-encryption and decryption Solved

35.00 $

Category:

Description

5/5 - (1 vote)

Task I  Write two Java* programs, one for encryption and the other for decryption, to implement TEA

(modified from Textbook): Perhaps the simplest “serious” symmetric block          L0                    R0 encryption algorithm is the Tiny Encryption Algorithm (TEA). TEA operates on 64- bit blocks of plaintext using a 128- bit key. The plaintext is divided into two 32- bit blocks (L0, R0), and the key is divided into four 32-bit blocks (K0, K1, K2, K3). As shown in the diagram, encryption involves repeated application of a pair of rounds, defined as follows for rounds i and i + 1 (i starts with 1):

Li = Ri-1                            Ri = Li-1 ⽥ F(Ri-1, K0, K1, δi)  

Li+1 = Ri                             Ri+1 = Li ⽥ F(Ri, K2, K3, δi+1) where F is defined as

F(X, Km, Kn, δy) = (( X << 4) ⽥ Km)  Å ( (X >> 5) ⽥ Kn) Å (X ⽥ δy)

and where the logical left shift of x by y bits is denoted by x << y; the logical R1 right shift of x by y bits is denoted by x >> y; δi (Deltai) is a sequence of predetermined constants; and ⽥ denotes addition-mod-232.

  1. If only one pair of rounds, i.e., rounds 1 and 2, is used, then the ciphertext is the 64- bit block (L2, R2). You may express the encryption algorithm by representing L2 as a function of L0, R0, K0, K1, and δ1, and representing R2 as a function of L2, R0, K2, K3, and δ2.

 

  1. The decryption algorithm is given as below. You may verify it by reverting the calculation in the block diagram.

R0 = R2 ⽈ [[(L2 << 4) ⽥ K2] Å [L2 ⽥ δ2] Å [(L2 >> 5) ⽥ K3]] L0 = L2 ⽈ [[(R0 << 4) ⽥ K0] Å [R0 ⽥ δ1] Å [(R0 >> 5) ⽥ K1]] where  ⽈ denotes subtraction-mod-232.

 

Program TEA_Encryption: Write a Java program to implement TEA Encryption including only one pair of rounds: rounds 1 and 2 •   Data and inputs:  o           declare a constant int DeltaOne with a hex value of 0x11111111 o       declare a constant int DeltaTwo with a hex value of 0x22222222

o    declare an int array with 4 elements: K[0], K[1], K[2], and K[3], get their values via user inputs in Hex strings

For each element K[i], where i = 0, 1, 2, or 3, display the following prompt message, read the user input as a String, and then convert the user input String into an integer by treating it as a Hex value, and assign this integer to K[i]. E.g., if the user input is “F3579BD1” for K[0], then K[0] = 0xF3579BD1.

Please input K[i] in Hex String (without “0x”): o declare two int arrays L[ ] and R[ ], each having a size of 3.

MSU Denver, M&CS                                           CS 3750: Computer and Network Security, Fall 2019                                              Dr. Weiying Zhu

For each of L[0] and R[0], display a prompt message like the following one for L[0], read the user input as a String, and then convert the user input String into an integer by treating it as a Hex value, and assign this integer to L[0] or R[0]. E.g., if the user input is “2468ACE0” for L[0], then L[0] = 0x2468ACE0.

Please input L[0] in Hex String (without “0x”):

Initialize L[1], L[2], R[1], and R[2] as 0x00000000’s.

  • The program and outputs: o Implement the encryption algorithm to calculate L[1] and R[1] first, and then L[2] and R[2]
    • Display the hex values of L[i] and R[i], where i = 0, 1, and 2, in Hex strings. E.g., assuming L[0] = 0x2468ACE0,

L[0] = 2468ACE0      R[0] = …… L[1] = ……            R[1] = ……

L[2] = ……            R[2] = ……

 

Program TEA_Decryption: Write a Java program to implement TEA Decryption including only one pair of rounds: rounds 1 and 2 •   Data and inputs:  o           declare a constant int DeltaOne with a hex value of 0x11111111 o       declare a constant int DeltaTwo with a hex value of 0x22222222

  • declare an int array with 4 elements: K[0], K[1], K[2], and K[3], get their values via user inputs in Hex strings

For each element K[i], where i = 0, 1, 2, or 3, display the following prompt message, read the user input as a String, and then convert the user input String into an integer by treating it as a Hex value, and assign this integer to K[i]. E.g., if the user input is “F3579BD1” for K[0], then K[0] = 0xF3579BD1.

Please input K[i] in Hex String (without “0x”): o declare two int arrays L[ ] and R[ ], each having a size of 3.

For each of L[2] and R[2], display a prompt message like the following one for L[2], read the user input as a String, and then convert the user input String into an integer by treating it as a Hex value, and assign this integer to L[2] or R[2]. E.g., if the user input is “2468ACE0” for L[2], then L[2] = 0x2468ACE0.

Please input L[2] in Hex String (without “0x”):

Initialize L[0], L[1], R[0], and R[1] as 0x00000000’s.

  • The program and outputs: o Implement the decryption algorithm to calculate L[1] and R[1] first, and then L[0] and R[0]
    • Display the hex values of L[i] and R[i], where i = 2, 1, and 0, in Hex strings. E.g., assuming L[2] = 0x2468ACE0,

L[2] = 2468ACE0      R[2] = …… L[1] = ……            R[1] = …… L[0] = ……            R[0] = ……

 

Task II (10%): Test your program on the virtual server. 

  Warning:

to complete this part, especially when you work at home, you must first (1) connect to the MSUDenver VPN using

your student VPN account (please read “how to set up VPN for … for students” at https://msudenver.edu/vpn/); then (2) connect to the virtual server cs3750a.msudenver.edu using sftp and ssh command on MAC/Linux or PUTTY and PSFTP on Windows.  For details, you may refer to Lab 1, Part I.

  1. MAKE a directory “HW02” under your home directory on msdenver.edu.
  2. UPLOAD, COMPILE, and TEST your both programs under “HW02” on msdenver.edu.
  3. SAVE two files namedtxt” and “tst_Decryption.txt” under “HW02” on cs3750a.msudenver.edu, which captures the outputs of your programs as a proof that you have tested both programs on cs3750a. You can use the following commands to redirect the standard output (stdout) to a file on UNIX, Linux, or Mac, and view the contents of the file

javac prog_name.java    //compile .java file into byte code into .class file java prog_name_args | tee tst_Encryption.txt  //copy stdout to the given .txt file cat file-name      //display the file’s contents.

  1. If you work in a team of two students, you must put a txt file including both team members’ names under your HW2/ on cs3750a (both team members are required to complete Task II under their own home directories on cs3750a). For grading, I will randomly pick the submission in one of the two home directories of the team members on cs3750a, and then give both team members the same grade.

 

  • HW-2-etjagv.zip