Unformatted Attachment Preview
Task 1 (8 pts)
Now that you have a
working password checker, we will add some encryption so
that you can be a little bit safer when storing user
passwords. In this task, you are to create a method
that implements a Caesar cipher.
A Caesar cipher is an old and very insecure method of
encryption. It involves shifting characters in order to
create a new string. For example, if the input string
is “abc” then the output string would be “bcd” (see that
every character was shifted 1 position to the right). If we
wanted to revert the encrypted string back to the original,
we would simply shift it 1 to the left.
The number of positions to shift is referred to as the key. So
if the key is 3, then we would shift right 3 to encrypt and
left 3 to decrypt.
Create a method that takes three arguments: a String
representing the plain text, an integer that represents the
key, and another integer that represents the mode (encrypt
or decrypt). Here, mode is 0 for encryption and 1 for
To make things easier, we will be dealing with ASCII characters
from the range of decimal 33 to decimal 126. You can find
the ASCII table here: http://www.asciitable.com/ This makes
the size of our alphabet to be 126 – 33 = 93. Cipher =
E(PlainText) = (PlainText + key) mod
alphabet_size PlainText = D(Cipher) = (Cipher – key) mod
Given the input string “TacoTuesday!12”: the first character
is ’T’ which is represented in the ASCII table as decimal
84. Our alphabet starts at decimal 33, so we need to first
subtract 33 so that our decimal representation of the
character lies within the appropriate range (0-92).
x = 84 – 33 = 51
Now we can use our key value and alphabet size to properly
convert this character as follows:
(x + key) mod alphabet_size = (51 + 1) mod 93 = 52
Now we have our encrypted character, looking up in the ASCII
table gives us the character ‘4’. Wait a minute… our key
was 1 meaning that we should have only shifted right by 1.
We would expect our encrypted character to be ‘U’. Remember
that we subtracted 33 from our value originally so that the
value lied within the appropriate range. All that is left
is to add 33 back to the number. 52 + 33 = 85
85 on the ASCII table converts to the letter ‘U’. Great! We
successfully encrypted the character.
To help you get started, you can use the following method
public static String caesarCipher(String text, int key, int
final int alphabetSize = 93;
// YOUR CODE
Task 2 (2 pts) Using your method from task 1, decrypt the
following strings using key =
15. rpt%pa@D0O r%t@B@?b”$x}v x}DBr’$B_p%%f!$s4m
Purchase answer to see full
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.Read more
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.Read more
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.Read more
Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.Read more
By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.Read more