Question: I had asked below question to expert at chegg and he gave me a code which was having error. I have mentioned both code and

I had asked below question to expert at chegg and he gave me a code which was having error. I have mentioned both code and error below. Please analyse and give me errorfree code which will give expected output as mentioned in question.
Question:
Implement one round of the simplified DES presented in section 7.2. Write a method that performs one
round of encryption. It takes as parameters a 12-bit input and an 8-bit key. It returns a 12-bit result.
Write a main method/main section that tests this method. I will provide test input/output pairs and
more details on implementation but you should have enough to start.
Added February 24th
Please also write a main method/main program that reads the plaintext and key, as decimal integers,
from the command line, calls the method described above passing it these values, and then prints the
resulting ciphertext. Call the program either sdesround.py or Sdesround.java.
For example, one should be able to run the program as either:
- python sdesround.py 1365170
- java Sdesround 1365170
And it will print the answer in both binary and decimal. In this case, it should print
Binary: 0b10101010000, decimal: 1360
Code which chegg provided me earlier:
public class Sdesround {
// Sample permutation and S-boxes (you may need to define your own based on DES)
static int[] perm ={1,0,3,2,5,4,7,6,9,8,11,10};
static int[] sbox ={0,1,1,0,1,0,0,1};
public static int encryptRound(int input, int key){
// Key mixing: XOR input with the key
int mixed = input ^ key;
// Substitution: Apply the S-box
int substituted = sbox[mixed];
// Permutation: Apply the permutation
int permuted =0;
for (int i =0; i <12; i++){
permuted |=((substituted >> i) & 1)<< perm[i];
}
return permuted;
}
public static void main(String[] args){
if (args.length <2){
System.out.println("Usage: java Sdesround

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!