Question
in c++ The science of writing secret codes is called cryptography. For thousands of years cryptography has made secret messages that only the sender and
in c++
The science of writing secret codes is called cryptography. For thousands of years cryptography has made secret messages that only the sender and recipient could read, even if someone captured the messenger and read the coded message. A secret code system is called a cipher.
In cryptography, we call the message that we want to be secret the plaintext. The plaintext could look like this: Hello there! The keys to the house are hidden under the flower pot.
Converting the plaintext into the encoded message is called encrypting the plaintext. The plaintext is encrypted into the ciphertext.
The ciphertext looks like random letters, and we cannot understand what the original plaintext was just by looking at the ciphertext.
Here is the previous example encrypted into ciphertext: Yvccf kyviv! Kyv bvpj kf kyv yfljv riv yzuuve leuvi kyv wcfnvi gfk.
But if you know about the cipher used to encrypt the message, you can decrypt the ciphertext back to the plaintext. (Decryption is the opposite of encryption.)
Many ciphers also use keys. Keys are secret values that let you decrypt ciphertext that was encrypted using a specific cipher.
Think of the cipher as being like a door lock. You can only unlock it with a particular key.
You will write a C++ program to encrypt a message by taking each letter in the message (in cryptography, these letters are called symbols because they can be letters ( A-Z) ,
numbers( 0-9) ) and replacing it with a shifted letter.
Using letters are , If you shift the letter A by one space, you get the letter B. If you shift the letter A by two spaces, you get the letter C.
If you encrypt the plaintext Howdy with a key of 3, then:
The H becomes K.
The letter o becomes r.
The letter w becomes z.
The letter d becomes g.
The letter y becomes b
The ciphertext of Howdy with key 3 becomes Krzgb
We will keep any non-letter characters the same. To decrypt Krzgb with the key 3, we go from the bottom boxes back to the top:
The letter K becomes H.
The letter r becomes o.
The letter z becomes w.
The letter g becomes d.
The letter b becomes y.
Here is a sample run of the cipher program, encrypting a message:
Do you wish to encrypt or decrypt a message?
encrypt
Enter your message:
The sky above the port was the color of television, tuned to a dead channel.
Enter the key number (1-26)
13
Your translated text is:
Gur fxl nobir gur cbeg jnf gur pbybe bs gryrivfvba, gharq gb n qrnq punaary.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started