Question: Write a program called SDESencrypt.java or sdesencrypt.py that performs the entire SDES encryption algorithm. You may use the method you wrote in the last assignment.

Write a program called SDESencrypt.java or sdesencrypt.py that performs the entire SDES encryption
algorithm. You may use the method you wrote in the last assignment. You will need to:
add a method that takes as a parameter the 9-bit input key and that returns a list of the four 8-
bit sub-keys
add a method that takes as parameters the 12-bit input plaintext and the 9-bit input key and
that returns the 12-bit ciphertext
As usual, write a main method/main section that gets the plaintext and the key as integer values from
command line parameters. It calls the second method described above and then prints the ciphertext as
a decimal integer and as a binary string.
Last Program was
public class Sdesround {
private static in assignment final int[][] S1={
{0,0,0,0,0,0,0,0},// Row 0
{1,0,1,0,1,0,1,0}// Row 1
};
private static final int[][] S2={
{4,2,4,0,2,0,0,0},// Row 0
{0,0,3,0,5,2,0,0}// Row 1
};
// Expand 6 bits to eight bits by the predefined method.
private static int expand(int input){
return (input & 0b100000)>>2|
(input & 0b010000)>>1|
(input & 0b001000)|
(input & 0b000100)1|
(input & 0b000010)2|
(input & 0b000010)3|
(input & 0b000001)4|
(input & 0b000001)5;
}
// Function f(Ri-1, Ki).
private static int functionF(int input, int key){
int expandedInput = expand(input);
int temp = expandedInput ^ key;
// Split temp into two 4-bit values for the S-boxes.
int left4=(temp >>4) & 0b1111;
int right4= temp & 0b1111;
// Determine the row and column for S1 and S2.
int row1=(left4>>3) & 0b1;
int row2=(right4>>3) & 0b1;
int col1= left4 & 0b111;
int col2= right4 & 0b111;
// Get values from S-boxes and concatenate.
return (S1[row1][col1]3)| S2[row2][col2];
}
// Round of simplified DES.
public static int desRound(int input, int key){
int L0=(input >>6) & 0b111111;
int R0= input & 0b111111;
int R1= L0^ functionF(R0, key);
int L1= R0; // As per definition Li = Ri-1
return (L16)| R1;
}
public static void main(String[] args){
if (args.length !=2){
System.out.println("Usage: java Sdesround 12-bit input as integer>9-bit key as integer>");
return;
}
// Convert input to integers
int input = Integer.parseInt(args[0]);
int key = Integer.parseInt(args[1]);
// Validate bit length
if (input >0b111111111111|| key >0b111111111){
System.out.println("Input must be a 12-bit integer and key must be a 9-bit integer.");
return;
}
// one round of simplified DES encryption
int result = desRound(input, getRoundKey(key,1)); // Assuming round '1' here for simplicity
// Print binary and decimal representations of the result
System.out.println("Binary: 0b"+ Integer.toBinaryString(result)+", decimal: "+ result);
}
// Function to get the Ki for the ith round
private static int getRoundKey(int key, int round){
// Left circular shift
int roundShift = round %9; // There are 9 bits in the key
return ((key roundShift)|(key >>(9- roundShift))) & 0b11111111;
}
}
 Write a program called SDESencrypt.java or sdesencrypt.py that performs the entire

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!