homework_04_question_.docx

Unformatted Attachment Preview

Don't use plagiarized sources. Get Your Custom Essay on
Just from \$10/Page

HOMEWORK 04     Task 1 (8 pts) Now that you have a
that you can be a little bit safer when storing user
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
decryption.
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
alphabet_size
Example
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.
declaration:
public static String caesarCipher(String text, int key, int
mode) {
final int alphabetSize = 93;
HERE
}
following strings using key =
15.  rpt%pa@D0O  r%t@B@?b”\$x}v x}DBr’\$B_p%%f!\$s4m

attachment

## Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
\$26
The price is based on these factors:
Number of pages
Urgency
Basic features
• Free title page and bibliography
• Unlimited revisions
• Plagiarism-free guarantee
• Money-back guarantee
On-demand options
• Writer’s samples
• Part-by-part delivery
• Overnight delivery
• Copies of used sources
Paper format
• 275 words per page
• 12 pt Arial/Times New Roman
• Double line spacing
• Any citation style (APA, MLA, Chicago/Turabian, Harvard)

# Our guarantees

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.

### Money-back guarantee

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.

### Zero-plagiarism guarantee

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.

### Free-revision policy

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.