Question

Need to finish the des_round method JAVA expands 6-bit r-input to 8-bits.  The 8 bits should be:...

Need to finish the des_round method JAVA

  1. expands 6-bit r-input to 8-bits.  The 8 bits should be: (1) (2) (4) (3) (4) (3) (5) (6) of original 6-bit input
  2. generates round key based on the master key and round number
  3. passes the expanded_r and round key to f(), which:
    3a. XORs them together;
    3b. Splits result into two 4-bit sequences
    3c. Refer to the 2 S-Boxes (row = bit 1; column = bits 2-4) to get two 3-bit outputs
    3d. Concatenates together to single 6-bit output
  4. XORs result of f() with original left-input. This result is the right part of output
  5. Combine with original right-input (which is the left part of the output)

import java.util.ArrayList;
import java.util.Collections;

public class DESMethod
{
private static int sbox1[][] = {
{0b101, 0b010, 0b001, 0b110, 0b011, 0b100, 0b111, 0b000}, // row 0
{0b001, 0b100, 0b110, 0b010, 0b000, 0b111, 0b101, 0b011} // row 1
};
private static int sbox2[][] = {
{0b100, 0b000, 0b110, 0b101, 0b111, 0b001, 0b011, 0b010}, // row 0
{0b101, 0b011, 0b000, 0b111, 0b110, 0b010, 0b001, 0b100} // row 1
};

public static void main(String[] args)
{   
int input = 0b011100100110;
int masterkey = 0b010011001;
int round = 4;

int result = des_round(input, masterkey,round);
}

//des_round() -- Performs a single round of simplified DES algorith on given input pt,  for round, using masterkey.
public static int des_round(int pt, int masterkey, int round)
{
//isolate the left and right halves of the input
//use bitwise AND operation to isolate the bits we want (upper 6 for left, lower 6 for right)
int l_in = (pt & 0b11111100000) >> 6; //need to right shift 6 spots so result is in lower 6 bits
int r_in = (pt & 0b000000111111);
  

//Print out results of the round (the round input, the round key, and the round output

  
}


}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;
import java.util.Collections;

public class DESMethod {
    private static int sbox1[][] = { { 0b101, 0b010, 0b001, 0b110, 0b011, 0b100, 0b111, 0b000 }, // row 0
            { 0b001, 0b100, 0b110, 0b010, 0b000, 0b111, 0b101, 0b011 } // row 1
    };
    private static int sbox2[][] = { { 0b100, 0b000, 0b110, 0b101, 0b111, 0b001, 0b011, 0b010 }, // row 0
            { 0b101, 0b011, 0b000, 0b111, 0b110, 0b010, 0b001, 0b100 } // row 1
    };

    public static void main(String[] args) {
        int input = 0b011100100110;
        int masterkey = 0b010011001;
        int round = 4;

        int result = des_round(input, masterkey, round);
        System.out.println(result);
    }
    
    static int getKeyForRound(int key, int round) {
        if(round == 1) {
            return (key & 0b111111110) >> 1;
        }
        int firstBit = key & 0b100000000;
        key = key << 1;
        key = key | (firstBit >> 8);
        return getKeyForRound(key, round - 1);
    }
    
    static int expanded_r(int x) {
        String s = Integer.toBinaryString(x);
        while(s.length() < 6) {
            s = "0" + s;
        }
        s = s.substring(0, 2) + s.charAt(3) + s.substring(2, 4) + s.charAt(2) + s.substring(4);
        return Integer.parseInt(s, 2);
    }

    //des_round() -- Performs a single round of simplified DES algorith on given input pt,  for round, using masterkey.
    public static int des_round(int pt, int masterkey, int round) {
        //isolate the left and right halves of the input
        //use bitwise AND operation to isolate the bits we want (upper 6 for left, lower 6 for right)
        int l_in = (pt & 0b111111000000) >> 6; // need to right shift 6 spots so result is in lower 6 bits
        int r_in = (pt & 0b000000111111);

        //Print out results of the round (the round input, the round key, and the round output
        int roundKey = getKeyForRound(masterkey, round);
        int erIn = expanded_r(r_in);
        
        int xored = erIn ^ roundKey;
        int s1 = (xored & 0b11110000) >> 4;
        int s2 = (xored & 0b00001111);
        
        int l_out = r_in;
        int r1 = (s1 & 0b1000) >> 3;
        int c1 = s1 & 0b0111;
        int r2 = (s2 & 0b1000) >> 3;
        int c2 = s2 & 0b0111;
        
        int r_Out = l_in ^ ((sbox1[r1][c1] << 3)| (sbox2[r2][c2]));
        return (l_out << 6) | r_Out;
    }

}

**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
Need to finish the des_round method JAVA expands 6-bit r-input to 8-bits.  The 8 bits should be:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in java, finish the method 17: Chapter 8: Handling a number as different types (Method Overloading)...

    in java, finish the method 17: Chapter 8: Handling a number as different types (Method Overloading) J o pulli UCILISIS lule zyBooks catalog Help/FAQ 31.47 Chapter 8: Handling a number as different types (Method Overloading) Write an overloaded method called divide_by_two() that can handle a number between 1-5 as an int, double, or String. • The method should be able to handle the String version with upper or lower case letters in any location in the String. ACTIVITY 31.47.1: Chapter...

  • JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but...

    JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but i need to create a jar file . the instructions are below. It has to pass some parameters. I am really confused on doing so.l I dont know what to do next. Can someone help me and give detailed descritiopm opn how you ran the jar file in CMD import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Connect4 {               ...

  • Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the...

    Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...

  • This is java. Goal is to create a pacman type game. I have most of the...

    This is java. Goal is to create a pacman type game. I have most of the code done just need to add in ghosts score dots etc. Attached is the assignment, and after the assignment is my current code. import java.awt.Color; import java.awt.Dimension; import java.awt.Image; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class Maze extends JFrame implements KeyListener { private static final String[] FILE = {...

  • I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT w...

    I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT with the implementation of your choice (Array or Link), it should not make a difference 2.Read two “integer” numbers from the user. Hint: You don’t need to use an int type when you read, it may be easier to parse the input...

  • Need help with this Java. I need help with the "to do" sections. Theres two parts...

    Need help with this Java. I need help with the "to do" sections. Theres two parts to this and I added the photos with the entire question Lab14 Part 1: 1) change the XXX to a number in the list, and YYY to a number // not in the list 2.code a call to linearSearch with the item number (XXX) // that is in the list; store the return in the variable result 3. change both XXX numbers to the...

  • Hi, So I have a finished class for the most part aside of the toFile method...

    Hi, So I have a finished class for the most part aside of the toFile method that takes a file absolute path +file name and writes to that file. I'd like to write everything that is in my run method also the toFile method. (They are the last two methods in the class). When I write to the file this is what I get. Instead of the desired That I get to my counsel. I am having trouble writing my...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Implement a Java method named addBinary() that takes two String arguments (each representing a binary value)...

    Implement a Java method named addBinary() that takes two String arguments (each representing a binary value) and returns a new String corresponding to the result of performing binary addition on those arguments. Before you begin, if one of the arguments is shorter than the other, call your pad() method from the previous step to extend it to the desired length. Note: ped() method is public static String pad(String input, int size) { if(input.length()>=size) { return input; } String a =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT