Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a stream cipher program starting from the sample program attached. Do the following steps: Study the attached sample program (XOR.java) and understand what it

Develop a stream cipher program starting from the sample program attached. Do the following steps:

  1. Study the attached sample program (XOR.java) and understand what it does. This program of course has some security problems. Find and fix those. (40 points)
  2. Change the program such that the seed for the random number generator can be set by deriving from the user input. (5 points)
  3. Read a block of text from keyboard and perform double xor encryption. Make sure that the information remains encrypted after the two encryptions. (Please print the ciphertext after each encryption. If some characters are not printable, printing in binary/hex will help you see the ciphertext.) (20 points)
  4. Perform double decryptions; Check and make sure the ciphertext indeed decrypts to plaintext by printing it. (10 points)
  5. Compute the effective key that can decrypt the ciphertext in a single decryption rather than two separate decryptions; print the effective key in binary. (5 points)
  6. Demonstrate that the effective key can decrypt the ciphertext generated in step c with a single decryption rather than two decryptions. (5 points)
  7. Does double encryption really improve security? Explain your answer. (5 points)
  8. Perform double encryption again; this time after the first XOR encryption though, add a byte transposition stage, and then do the second XOR encryption. (extra credit) (5 points)
  9. Decrypt the ciphertext generated in step g and obtain the plaintext. (extra credit) (5 points)
  10. Assuming that you did step g (even if you didn't do the extra credit part), do you think the effective key (used in step f) will decrypt the ciphertext generated in step g? Explain. (5 points)
  11. If the keys are never reused, do you think adding transposition stage in between two encryptions can increase security? Explain. (5 points)
  12. Submit the (.java) source code

You should do all of the above in one .java file; make sure you display plaintext, ciphertext (in binary), key (in binary) as appropriate after every step to indicate what happens inside your program.

Please attach additional explanation or answers to questions above (steps g, j and k) as a separate PDF/Word/Text document.

//XOR.java import java.util.Scanner; import java.security.SecureRandom; import java.math.BigInteger; class XOR{ public static void main (String args[]) { try { //Read a line from keyboard Scanner in = new Scanner(System.in); //define scanner for input String messageString; System.out.println("Please enter the message:"); messageString=in.nextLine(); //read a line System.out.println("Original Message: "+ messageString); BigInteger message = convertStringToBigInteger(messageString); //Set up a secure random number generator SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); int seed = 10; random.setSeed(seed); //initilize the random number generator //Generate Key (Warning! botched) byte [] keyStream = new byte[2]; random.nextBytes(keyStream); //generate random bytes in put in keyStream BigInteger key = new BigInteger(keyStream); //XOR encryption -- Sender's (Alice's) end BigInteger cipherText = message.xor(key); //Convert ciphertext to a string so that we can print it System.out.println("plaintext (in binary):" + message.toString(2)); System.out.println("key (in binary):" + key.toString(2)); System.out.println("ciphertext (in binary):" + cipherText.toString(2)); System.out.println("Ciphertext (in characters): "+ convertBigIntegerToString(cipherText)); //XOR decryption -- Receiver's end (Bob's end) BigInteger receivedMessage = cipherText.xor(key); String receivedMessageString = convertBigIntegerToString(receivedMessage); System.out.println("Received Message: "+ receivedMessageString); } catch (Exception e) { e.printStackTrace(); } } //This is a method to convert a String to BigInteger by //packing each character into a BigInteger //Input: String //Output: BigInteger public static BigInteger convertStringToBigInteger(String s) { BigInteger b = new BigInteger("0"); for (int i = 0; i < s.length(); i++) { Integer code = new Integer((int)s.charAt(i)); BigInteger c = new BigInteger(code.toString()); b = b.shiftLeft(8); b = b.or(c); } return b; } //This is a method to convert a BigInteger to String //by converting each byte into a character and forming //a string of characters. //Input: BigInteger //Output: String public static String convertBigIntegerToString(BigInteger b) { String s = new String(); while (b.compareTo(BigInteger.ZERO) == 1) { BigInteger c = new BigInteger("11111111", 2); int cb = (b.and(c)).intValue(); Character cv= new Character((char)cb); s = (cv.toString()).concat(s); b = b.shiftRight(8); } return s; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions