in C++ language Magic Decoder Ring. A one-time pad is a coding device that uses each character of a key string only once to encode and decode a corresponding character in a message string. Thus, the first character in the key is used to encode and decode the first character in the clear message, the second character in the key is used with the second character in the message, etc. No portion of the key is reused in subsequent messages, making for a very solid coding system, assuming a randomly generated key. You will need to create a class titled MagicDecoderRing that contains the variables and functions needed for obtaining the clear and key texts, encoding and decoding the messages, writing out the encoded message etc. You will need to instantiate an instance of this class in your main function to run your program and encode and decode messages. You need to further break your MagicDecoderRing code down into many small functions that each can be described with a single sentence without ‘ands” and “ors.” You are probably going to at least need functions with names such as encodeChar, decodeChar, encodeStr, decodeStr. Use notepad to develop two different files containing the clear-text original message and the key string. Write a program that first reads in the clear.txt and key.txt files and generates a third file, encoded.txt, containing the encoded message which is also displayed to the user. All three files are closed as soon as possible after being opened. The program then reads in the key and encoded files and displays the original clear text. Be sure to use local paths so that when the program folder is moved to a different location, things still work. The encoded text is created from the clear text and key string by combining the ith character in the clear text and the ith character in the key string to create the ith character in the resulting encoded message as follows: Take the ascii values of the ith character in the clear text and subtract the ith character in the key string, plus 256 (why?) mod 256 to generate a number between 0 and 255 which becomes the ith character in the encoded text. To decode the encoded text, the ith character in the key string is added to the ith character in the encoded text  mod 256 and converted back into a character to determine the ith character in the original clear text. An example might be useful. Suppose the 75th character in the clear message is "c" with an ascii value of 99 and suppose the 75th character in the key string is "#" with ASCII value 35.  (90-35+256) modules (%) 256 = 64. To decode we add 64 to 35 modulus 256 and get back 99 and our original character "c". The above encoding and decoding assumes that the key string (created from the key.txt file) is at least as long as the clear text. To insure this is the case, you should check string lengths and if needed concatenate the key string with itself a sufficient number of times until it is longer than the clear text. Note, while this does keep things working, it is bad encryption practice as the key is then used more than once, making the code easier to break.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section9.3: The String Class
Problem 7E
icon
Related questions
Question

in C++ language

Magic Decoder Ring. A one-time pad is a coding device that uses each character of a key string only once to encode and decode a corresponding character in a message string. Thus, the first character in the key is used to encode and decode the first character in the clear message, the second character in the key is used with the second character in the message, etc. No portion of the key is reused in subsequent messages, making for a very solid coding system, assuming a randomly generated key.

You will need to create a class titled MagicDecoderRing that contains the variables and functions needed for obtaining the clear and key texts, encoding and decoding the messages, writing out the encoded message etc. You will need to instantiate an instance of this class in your main function to run your program and encode and decode messages. You need to further break your MagicDecoderRing code down into many small functions that each can be described with a single sentence without ‘ands” and “ors.” You are probably going to at least need functions with names such as encodeChar, decodeChar, encodeStr, decodeStr.

Use notepad to develop two different files containing the clear-text original message and the key string. Write a program that first reads in the clear.txt and key.txt files and generates a third file, encoded.txt, containing the encoded message which is also displayed to the user. All three files are closed as soon as possible after being opened. The program then reads in the key and encoded files and displays the original clear text. Be sure to use local paths so that when the program folder is moved to a different location, things still work.

The encoded text is created from the clear text and key string by combining the ith character in the clear text and the ith character in the key string to create the ith character in the resulting encoded message as follows: Take the ascii values of the ith character in the clear text and subtract the ith character in the key string, plus 256 (why?) mod 256 to generate a number between 0 and 255 which becomes the ith character in the encoded text. To decode the encoded text, the ith character in the key string is added to the ith character in the encoded text  mod 256 and converted back into a character to determine the ith character in the original clear text.

An example might be useful. Suppose the 75th character in the clear message is "c" with an ascii value of 99 and suppose the 75th character in the key string is "#" with ASCII value 35.  (90-35+256) modules (%) 256 = 64. To decode we add 64 to 35 modulus 256 and get back 99 and our original character "c".

The above encoding and decoding assumes that the key string (created from the key.txt file) is at least as long as the clear text. To insure this is the case, you should check string lengths and if needed concatenate the key string with itself a sufficient number of times until it is longer than the clear text. Note, while this does keep things working, it is bad encryption practice as the key is then used more than once, making the code easier to break.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 1 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning