What is the data type to store user inputted bitwise operator

I have implemented Data Encryption Standard(DES) to encrypt a plain text and get the cipher from it. Though the DES uses 56 bit key , 64 bit block size and 16 rounds, to start from a simple code. I used 4 bit key, 8 bit block size, 4 rounds and without sub key generation (i.e. same key is used in all the rounds). According to DES for each an every round a round function is used. In my case I used the bitwise AND (&) operator.

Here is a portion of my code

import java.util.Arrays;

public class Encrypt {
    private int key[]={1,0,1,0};
    private int dataBlock[]={1,1,1,0,1,0,1,1};
    private int dataLeft[]=new int [4]; // for left part the plain text 
    private int dataRight[]=new int [4];    //for right part of the plain text
    private int dataLeftTemp[];
    private int dataRightTemp[]=new int [4];
    private int i=2;    // as initially two steps are run through automatically
    private int n=5;    // the no of rounds
    private int cipher[];

    public void splitting(){
        int j=0;        // for setting the indexes of the dataRight[]
        for(int i=0;i<dataBlock.length;i++){

            if (i<(dataBlock.length/2)){


            //           when i is greater than the half the index of the plain text

        // for printing the array-------------------------------------------------  
        for(int i: dataLeft){
        for(int i: dataRight){
        System.out.println(" ");
        System.out.println(" ");

    //==============================round function================================================

    public void roundingStart(){
        System.out.println("Enter the round function");

        for(int i=0;i<4;i++){
            //           AND function
            dataRightTemp[i]=key[i] & dataRight[i];
            //              XOR function


        //      printResults();


//rest of the code

This works fine. But how do I change the above code so that user can enter the bitwise operator that is to be used in the round function. I tried using Scanner but I don’t know what data type to be used to store the user input as bitwise operator so that it can be used at line

dataRightTemp[i]=key[i] & dataRight[i];

Can someone explain me how to do this?


you cannot store the operator itself.

instead let the user input the operator as text: e.g. and, or , .. and in your code use an if-statement to use the correct operator based on this user-text. Pseudocode:

if ("and".equalsIgnoreCase(userInput) {
     dataRightTemp[i]=key[i] & dataRight[i];
} else if ("or".equalsIgnoreCase(userInput)) {
     dataRightTemp[i]=key[i] | dataRight[i];

Leave a Reply

Your email address will not be published. Required fields are marked *