Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment No 1 -- Stream Cipher (XOR Encryption) Hide Folder Information Instructions Develop a stream cipher program starting from the sample program attached. Do the

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Assignment No 1 -- Stream Cipher (XOR Encryption) Hide Folder Information Instructions Develop a stream cipher program starting from the sample program attached. Do the following steps a. 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) b. Change the program such that the seed for the random number generator can be set by deriving from the user input. (5 points) c. 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) d. Perform double decryptions; Check and make sure the ciphertext indeed decrypts to plaintext by printing it. (10 points) e. 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) f. Demonstrate that the effective key can decrypt the ciphertext generated in step c with a single decryption rather than two decryptions. (5 points) g. Does double encryption really improve security? Explain your answer. (5 points) h. 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) i. Decrypt the ciphertext generated in step g and obtain the plaintext. (extra credit) (5 points) j. 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) k. If the keys are never reused, do you think adding transposition stage in between two encryptions can increase security? Explain. points) (5 I. 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. Extra credit steps are worth up to 10 points. Extra credit may be applied in the category of assignments The above description is by no means complete. Ask questions in February 19 (Tuesday's) class. And.. don't wait until the last minute You may start from XOR.java file. Whatever code you add to it should be written by you. import java.util.Scanner import java.security.SecureRandom; import java.math.Biglnteger; class XOR! public static void main (String argsI) try f //Read a line from keyboard Scanner in new Scanner(System.in)://define scanner for input String messageString: System.out.printin("Please enter the message:"T messageString-in.nextline)://read a line System.out.printin("Original Message: "+ messageString): Biginteger message convertStringToBigintegerlmessageString): //Set up a secure random number generator SecureRandom random SecureRandom getinstanceCHAPRNG"); int seed 10; random.setSeed(seed); //initilize the random number generator //Generate Key (Warning! botched) byte I keyStream new byte[2) random.nextBytes(keyStream)://generate random bytes in put in keyStream Biginteger key new Biginteger(keyStream) /IXOR encryption - Sender's (Alice's) end Biginteger cipherText message.xor(keyl: //Convert ciphertext to a string so that we can print it System.out.println("plaintext (in binary):"+ message.toStringl2)://displays message in binary System.out.printin("key (in binary):" + key.toString(2): //displays key in binary System.out.println("ciphertext (in binary):" + cipherText.toString(2))://displays ciphertext in binary System.out.printin("Ciphertext (in characters): "+ convertBigintegerToString(cipherText)): //XOR decryption- -Receiver's end (Bob's end Biginteger receivedMessage cipherText.xor(keyl String receivedMessageString convertBigintegerToString(receivedMessage); System.out.printin( Received Message: "+ receivedMessageString); catch (Exception e) f e.printStackTrace): //This is a method to convert a String to Biginteger by //packing each character of the String into a Biglinteger //Input: String //Return Value: Biginteger public static Biginteger convertStringToBiginteger(String s) Biginteger b new Bigintegerfo") for (int i 0:is.length0: i+) Integer code - new Integerl(lint)s.charAt(): Biginteger c -new Bigintegerfcode.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 //Return Value: String public static String convertBigintegerToString(Biginteger b) String s new String(): while (b.compareTo(Biginteger.ZERO)1) int cb (b.and(c)).intValue): Character cv new Characterl(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

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

7. Understand the challenges of multilingualism.

Answered: 1 week ago