APS101: Assignment 2, Encryption Algorithm (Note: this is a simplified version of a real algorithm, called the "one-time pad". You can read about it here: http://www.cs.toronto.edu/~rackoff/2426f08/notes0.pdf It is briefly described at the bottom of page 2.) You are given: - a message M (a String of characters) - a key K (typically a 4-digit integer - e.g., a debit card PIN, or the Spy's code number) To encrypt message M, follow these steps: 1) Convert message M into a String of 8-bit binary values. In other words, convert each character in M into an 8-bit binary String that represents the character's ASCII value (hint: use the "charToBinary" method for this). Ex. message "ha" would be "0110100001100001". Notice that there is one "0" before "1101000" (which is the binary representation of 'h'). The reason for this is that the actual binary value is only 7 bits long, but we need it to be 8 bits, so we "pad" it with 0's. 2) Convert the key K into a 16-bit binary String value. Don't forget to "pad" it with 0's (if necessary) so it is EXACTLY 16 bits long. You don't have to worry about integer values of K whose binary representation is greater than 16 bits. Ex. key 1234 would be "0000010011010010". 3) Make the binary representation of K longer, by stretching it from 16-bits to 128-bits. Do this by concatenating the 16-bit string with itself 8 times. Ex. the 16-bit key "0000010011010010" would be: "00000100110100100000010011010010000001001101001000000100110100100000010011010010000001001101001000000100110100100000010011010010" 4) If the new 128-bit key is still shorter than the length of the binary represenation of message M from step 1), then use the "stretch" method to make the key AT LEAST as long as the binary representation of M. 5) Create an encrypted binary String of the same length as the binary representation of M. Do this by applying the exclusive-or (XOR) operator to each bit of the message and the corresponding bits of the key (hint: use the "exclusiveOr" method for this). Note that after step 4), the key might actually be longer than the message. Don't worry about this - just use the first |M| bits of the key. Ex. M = "1011" K = "01101101" Result = "1101" 6) Return the result from step 5) as it is. In other words, return the |M|-bit binary String as the encryption of the message. You DON'T have to convert each 8-bits of the result from step 5) into a character.