Can't Figure Out Encode and Decode C++ Problem

I'm having some trouble figuring out a C++ problem in my book. This is the part I really don't understand: "Note that what you encode cannot be directly decoded, as there is not a one-to-one correspondence". The way I was going to try to do this was by assigning each character a value and checking that to output the code. I'm completely confused as to how to solve this.

Thanks for the help.

Here it is:

Background Info:

Introduction to: Strings and Dates
At some point virtually all computer programs have to come in contact with
human beings with whom they have to communicate to interact. And a primary vehicle for this is textual information. We know that computers use combinations of binary digits to represent letters, numbers, and other symbols [e.g., punctuation]. The coding system most commonly found today is called ASCII [American Standard Code for Information Interchange].

It turns out that when it has to deal with strings of characters C++ treats them as an array [an array with the base type of char.] Dates are a specialized representation of data, and are treated in a couple of ways.

Assignment:

I came across a puzzle in a magazine that required you to decode a message composed of Wingdings icons. So, using what you’ve learned so far about C++ and the image below, write a C++ program that takes a text string [this text can include only alphabetic and characters] as input from a user, and using the relationships between letters and numbers present on a rotary telephone dial, encode the message. For example, the text string ‘hello’ would become ‘43556’. You then output back to the user the encoded message. Note that what you encode cannot be directly decoded, as there is not a one-to-one correspondence. What the puzzle makes you do is look at the frequency of certain symbols and go through various permutations that form words
that might be valid translations.

There isn't really anything to solve, necessarily. You have a collection of data that gets operated on by an algorithm. The data is organized by an index, in this case the then number on the telephone. Each number has with it an associated string, or list of characters. here is the algorithm:

1234567

Get the input from the user
for each element in the input,
for each element in the array
if the input element is equal to the array element
append the value of the index to the encoded string
output the encoded string

usually an encoded message relies on some sort of letter to letter mutation. For example, the letter 'b' might be replaced with the letter 'a'. By knowing what the offset is, you can write a program that will decode the message. In this case the translation would be a character by character shift of the alphabet. This is a simple cypher, and is called a Caesar Shift.

xtllx xtllx xtllx h fns knud hm lx stllx

Since the type of encoding that you want to reproduce does not rely on a shifting of the alphabet, a mathematical interpretation is somewhat complex. The solution set for each element is three. the number 2 can either be 'a' or 'b' or 'c'. Since 1 can be any of the three letters, its difficult for the program to come to a reasonable outcome. This is where the human needs to interact with the result to know what the meaningful output is. The sentence "I like Brownies" means nothing to the computer. Its a string of numeric representations in memory:

73 108 105 107 101 66 114 111 110 105 101 115

These numbers have no meaning to the computer either. These numbers are representations of this:

I have to use the values on the phone in the image I posted, not ASCII. It's a rotary phone and it's not the same as a regular cell phone keyboard, but it's close. So for an example L would be 555 and J would be 5.

Yes, but when the user enters the string as the programmer you need to be able to determine what they entered. One of the ways you can do this is by using the ASCII values. So if the user inputted 'a' you need to know that, and you can check if they did by using the ASCII code for 'a', which is 97.

Does this make sense?

(nice. This is post 404. Can you see this post? Otherwise you'll need to contact the system administrator. lol)

Well, what you are doing is using the equivalent ASCII value to determine what the encoded character is. So for J and L the ASCII range would be 74 through 76. If the character is within this range, you add to the the encoded string a '5'.

I'm not sure if this is homework, but its better and easier to use the string class. to do so you'll need to include <string>.

123456789101112131415161718192021222324

#include <string>usingnamespace std;
#include "stdafx.h"#include <iostream>usingnamespace std;
int main ()
{
string Message;
string EncodedMessage;
cout << "Enter Text (without spaces): ";
cin >> Message;
for (int i = 0; i < Message.Length(); i++)
{
//here is where you want to check each position of the //string to see where it is in relation of the phone.// you do this by using the [] operator of the string class.
}
cout << "Encoded Message: " << EncodedMessage<< ".\n";
return 0;
}

I have to use the values on the phone in the image I posted, not ASCII. It's a rotary phone and it's not the same as a regular cell phone keyboard, but it's close. So for an example L would be 555 and J would be 5.