Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can You please do this in Java Decrypt shift cipher The following ciphertext was encrypted by a shift cipher: ycvejqwvhqtdtwvwu Write a program in Java

can You please do this in Java

Decrypt shift cipher

The following ciphertext was encrypted by a shift cipher:

ycvejqwvhqtdtwvwu

Write a program in Java or in Python that will try all possible shifts. Your output should must be

1:zdwfkrxwirueuxwxv

...

25:xbudipvugpscsvuvt
The plaintext was: plaintextgoeshere

(replace plaintextgoeshere with the actual recovered plaintext).

Note 1: your program does not have to decide what the correct output is. Once you have determined what the plaintext was, update your program to print out this last line.

Note 2: In order to receive full credit, your output MUST EXACTLY match the format printed above (including proper whitespace, etc.)


If you use Java, you may use the following code fragments in your program:

/**
* @return the ordinal value of a character c.
* This function disregards case, but does preserve it.
* Ordinal values are a=0, b=1, ..., z=25
*
* Preconditions: only valid characters are a-z and A-Z
*/
public static int charToOrd(char c) {
int value;
if (Character.isUpperCase(c))
value = (int)c - (int)'A';
else
value = (int)c - (int)'a';
assert value >= 0 : "Value too low";
assert value return value;
}

/**
* @returns the lower-case character matching the ordinal value o
* Ordinal values are a=0, b=1, ..., z=25
*
* Preconditions: only valid values are 0-25 (inclusive)
*/
public static char charToOrd(int o) {
if ( (o 25) ) throw new IllegalArgumentException();
return (char)(o + (int)'a');
}
image text in transcribed
image text in transcribed
The following cipher text was encrypted by a shift cipher: yovej qwwqtdtww Write a program in Java or in Python that will try all possible shifts. Your output should must be 11dw krxwirueuxwxV 25:xbudipvugpscsvut The plaintext wan: plaintextgooshere (replace plaintextgoethere with the actual recovered plaintext). Note 1: your program does not have to decide what the correct output is. Once you have determined what the plaintext was, update your program to print out this last line. Note 2: In order to receive full credit, your output MUST EXACTLY match the format printed above (including proper whitespace, etc.) If you use Java, you may use the following code fragments in your program: * @return the ordinal value of a character c. * This function disregards case, but does preserve it. * Ordinal values are a=0, b=1, ..., z=25 * Preconditions: only valid characters are a-z and A-Z public static int chartoord (char c) { int value; if (Character. isUpperCase(c)) value = (int) - (int) 'A'; else value = (int) - (int) 'a'; assert value >= 0 : "Value too low"; assert value 25)) throw new IllegalArgumentException(); return (char) (o + (int) 'a'); }

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

Intelligent Information And Database Systems Second International Conference Acids Hue City Vietnam March 2010 Proceedings Part 1 Lnai 5990

Authors: Manh Thanh Le ,Jerzy Swiatek ,Ngoc Thanh Nguyen

2010th Edition

3642121446, 978-3642121449

More Books

Students also viewed these Databases questions