Your country is at war and your enemies are using a secret code to communicate with one another. You have managed to intercept a message that reads as follows:
:mmZ\dxZmx] Zpgy
The message is obviously encrypted using the enemy’s secret code. You have just learned that their encryption method is based upon the ASCII code (see Appendix 7). Individual characters in a string are encoded using this system. For example, the character ‘A’ is encoded using the number 65 and ‘B’ is encoded using the number 66. Your enemy’s secret code takes each letter of the message and encrypts it as follows:
if (OriginalChar + Key > 126) then
EncryptedChar = 32 + ((OriginalChar +Key) − 127)
else
EncryptedChar = (OriginalChar + Key)
For example, if the enemy uses Key = 10 then the message “Hey” would initially be represented as:
Character ASCII code
H 72.
e 101
y 121
And “Hey” would be encrypted as:
Encrypted H − (72 + 10) − 02 − R in ASCII
Encrypted e − (101 + 10) – 111 − o in ASCII
Encrypted y = 32 + ((121 + 10) − 127) = 36 = $ in ASCII
Consequently, “Hey” would be transmitted as “Ro$.” Write a Java program that decrypts the intercepted message. You only know that the key used is a number between 1 and 100. You can assume that the original message consists entirely of ASCII codes that represent only printable characters. Your program should try to decode the message using all possible keys between 1 and 100. When you try the valid key, the message will make sense. For all other keys, the message will appear as gibberish. Since there are only 100 keys this would obviously be a pretty crummy encryption system. This
You will want to use charAt ().
Important: Note that the secret code has a \ so you will need to escape encode it by using \\ if you hard-code it in your program.
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Starting Out With Visual Basic (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
C Programming Language
C++ How to Program (10th Edition)
- Given table is the ascii value of the characters and symbols. The following code is the code for XOR Encryption: Change the input string in the driver code at the sample string. def encrypt(inpString): xorKey = 'e' Which of the following is the message HELLO TUTOR after xor encryption, using 'e' as the key, has been applied? - ))*E101*7 -$55<E'H!$< =$(E7 3,6 - ),"*)$+!6 Which of the following is the message HELIGOLANDS after xor encryption, using 'e' as the key, has been applied? - )5E( E5)6 - ),"*)$+!6 - ))*E207)< - ))*E2*7)! Which of the following is the original message before xor encryption, using 'e' as the key, created - ),"*)$+!6? HELP ME PLS HELIGOLANDS HELLO WURLY HELLO WORLDarrow_forwardThis is a caesar encryption code, please help me with a code to reverse this operation (decrept it) in C++ string encrypt(string text, int s){ string result = ""; // traverse text for (int i=0;i<text.length();i++) { // apply transformation to each character // Encrypt Uppercase letters if (isupper(text[i])) result += char(int(text[i]+s-65)%26 +65); // Encrypt Lowercase letters else result += char(int(text[i]+s-97)%26 +97); } // Return the resulting string return result;} int main(){ string text; int s; cin>> text; cin >> s; cout << "Text : " << text; cout << "\nShift: " << s; cout << "\nCipher: " << encrypt(text, s); return 0;}arrow_forwardA. The original Caesar cypher shifts each character by one: a becomes b, z becomes a, and so on. Let's make it a bit harder, and allow the shifted value to come from the range 1..25 inclusive. Moreover, let the code preserve the letters' case (lower-case letters will remain lower-case) and all non-alphabetical characters should remain untouched. Your task is to write a program which: asks the user for one line of text to encrypt; asks the user for a shift value (an integer number from the range 1..25 - note: you should force the user to enter a valid shift value (don't give up and don't let bad data fool you!) Test your code using the data we've provided. Test data Sample input: abcxyzABCxyz 123 2 Sample output: cdezabCDEzab 123 Sample input: The die is cast 25 Sample output: Sgd chd hr bzrsarrow_forward
- PYTHON3 Complete the given function, encrypt_text that encrypts the variable text using the provided key by applying a modified version of Caesar’s Cipher with the following rules: The key will contain a word made up of the letters ‘u’ and ‘d’. The cipher will use the key to determine the direction of the shift, with a ‘u’ indicating that the character must be shifted upwards while a ‘d’ indicating a downward shift. The number of characters in the key will determine the number of positions to shift. The given text variable will only contain characters from the ASCII table with values between 32 and 126. If the key is invalid (empty string, contains characters other than u and d) or the text is invalid (empty string), no encryption occurs and the function returns the original text. If the text has more characters than the key, the key will loop through again to accommodate the additional text characters. An iterative approach should be used to solve this problem. Brute force…arrow_forwardPlease explain Python Code # 2) Write a procedure that takes a string and returns that string ROT13'ed.def rot13(word):encryptedword = ""for c in word:if c >= 'a' and c <= 'm': # a..mencryptedword += chr((ord(c)+13))elif c >= 'n' and c <= 'z': # n..zencryptedword += chr((ord(c)-13))else: # don't encrypt lettersencryptedword += creturn encryptedword#print(rconvertup("example"))print(rot13("example!"))print(rot13(rot13("example!")))arrow_forwardConvert the following string from INFIX to PREFIX: (A+B)^(C-D^E) + (F+G)/H* +^+AB-C^DE / +FGH +AB^-C^DE / +FGH AB+CDE^- ^ FG+H/+ AB+CDE^- ^ +FGH/ (AB)+CDE^- ^ (FGH)+/arrow_forward
- // Task 2 // For this function, you must build a string that when printed,// will output the entire binary representation of the integer x,// no matter how many bits an integer is. You may NOT use// division (/) or mod (%) anywhere in your code, and should// instead rely on bitwise operations to read the underlying binary// representation of x.stringbuilder get_bin_1(int x) { stringbuilder sb = new_sb(); sb_append(sb, '$'); return sb;}arrow_forwardIn C/C++, What is the range of values a unsigned int can hold on a computer where an integer is made up of 3 bits? Which of the following variable names is not considered to be of bad coding style? LARRY33 numberOfHorses NumberOfCows axvasdfarrow_forwardPlease write in C program to print out a list of bit strings that can be created by using combination How many bit strings of length 12 containa) exactly three 1s?b) at most three 1s?c) at least three 1s?d) an equal number of 0s and 1s?arrow_forward
- In a data file there are ten thousand characters of the following likein the picture. betty batter bought butter, the butter was not bitter butter, but the better butter. If you convert the characters in the binary sequence of 0, and 1using ASCII fixed-length code then what will be the total number ofbits?arrow_forwardPython The Dan Cipher works like this: shift the first lowercase character to the right by 1, the second lowercase character to the right by 2, and so on. Characters that are not lowercase characters are not changed. Write a program that takes a string and prints the result of applying the Dan Cipher.arrow_forwardThis is C++ AND i need it ASAP please 1: You will be given two positive integers, a and b (a <= b). • If 1<=n<=9, the print the English representation of it in lowercase. That is, “one” for 1,” two” for 2 and so on. • Else if n>9 and it is an even number then print “even”. • Else if n>9 and it is an odd number, then print “odd”. • Check that a>=b and a,b>0(Positive). Write cerr and return a non-zero value if this condition does not hold. Example: 8 11 Output : eight nine even odd #include <iostream> using namespace std; int main() { int a,b; cout << "Enter the first number:"; cin >> a; cout << "Enter the second number:"; cin >> b; //you code here }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education