Write two methods encrypt(message,key) and decrypt(message,key) to encrypt and decrypt messages with a key.
Write two methods encrypt(message,key) and decrypt(message,key) to encrypt and decrypt messages with a key.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 21PE
Related questions
Question
please write in JAVA
![Question 4
Write two methods
encrypt(message,key) and
decrypt(message,key)
to encrypt and decrypt messages with a key.
You are going to use ASCII values of each character. For example, the character 'A' is encoded using the
number 65 and 'B' is encoded using the number 66. Given a key, you will use the following method to
each letter of the message:
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
"Hey" would be converted to "Ro$:
Encrypted H = (72 + 10) = 82 = R in ASCII
Encrypted e = (101 + 10) = 111 = o in ASCII
Encrypted y = 32 + ((121 + 10) - 127) = 36 = $ in ASCII
After conversion, the converted message will be circularly shifted left 2 characters. For example, the
message “Hey" will be encrypted as "$Ro" after circular shift operation. The methods encrypt and
decrypt will return the following result:
encrypt("Hey", 10) → “$Ro"
decrypt("SRo", 10) > "Неy"
Suppose that key =17, encrypt and decrypt the following message texts. Print encrypted and decrypted
messages.
msg1 = "Lost time is never found again."
msg2 = "Use it or lose it."](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F25595ae9-9739-48ff-a0d0-76f9426a69e3%2F8a2807e5-0c15-4e63-8a77-4b3aa04d12dd%2Fh7ddui8_processed.png&w=3840&q=75)
Transcribed Image Text:Question 4
Write two methods
encrypt(message,key) and
decrypt(message,key)
to encrypt and decrypt messages with a key.
You are going to use ASCII values of each character. For example, the character 'A' is encoded using the
number 65 and 'B' is encoded using the number 66. Given a key, you will use the following method to
each letter of the message:
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
"Hey" would be converted to "Ro$:
Encrypted H = (72 + 10) = 82 = R in ASCII
Encrypted e = (101 + 10) = 111 = o in ASCII
Encrypted y = 32 + ((121 + 10) - 127) = 36 = $ in ASCII
After conversion, the converted message will be circularly shifted left 2 characters. For example, the
message “Hey" will be encrypted as "$Ro" after circular shift operation. The methods encrypt and
decrypt will return the following result:
encrypt("Hey", 10) → “$Ro"
decrypt("SRo", 10) > "Неy"
Suppose that key =17, encrypt and decrypt the following message texts. Print encrypted and decrypted
messages.
msg1 = "Lost time is never found again."
msg2 = "Use it or lose it."
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning