Plz help me how to solve CodeBreaker

Task 1: Encode and Decode
(a) [20%] void encode(int key, char plain[], int length, char encoded[]);
This function implements the encoding scheme described earlier, using the key passed as the first
argument. It steps through the array plain[] from index 0 to index length􀀃–􀀃1, encodes each character
and places the resulting value in the corresponding element of encoded[]. The array plain[] is not
changed.
Examples:
(i)
Breaking the code
Tasks
char message[2] = {'H', 'i'};
char encoded_message[2];
encode(1, message, 2, encoded_message);
for (int i = 0; i < 2; ++i)
{
cout << encoded_message[i];
}
cout << endl;

(b) [20%] void􀀃decode(int􀀃key,􀀃char􀀃encoded[],􀀃int􀀃length,􀀃char􀀃plain[]);
This function decodes characters back to plaintext. The key passed as the first argument is the key
used to perform the original encoding. The function steps through array encoded[] from index 0 to
index length􀀃–􀀃1, decodes each character and places the resulting value in the corresponding element
of plain[]. The array encoded[] is not changed.
Examples:
(i)
Produces the output:
(ii)
char message[2] = {'H', 'i'};
char encoded_message[2];
encode(90, message, 2, encoded_message);
for (int i = 0; i < 2; ++i)
{
cout << encoded_message[i];
}
cout << endl;
Ij
"C
char message[2];
char encoded_message[2] = {'I', 'j'};
decode(1, encoded_message, 2, message);
for (int i = 0; i < 2; ++i)
{
cout << message[i];
}
cout << endl;
Hi


May I ask how i can design a function to encode and decode it? Thanks a lot!
Last edited on
This function implements the encoding scheme described earlier

what is the encoding scheme?
encoding scheme? What do you mean?
there are many ways to encode something
what is the way you are supposed to encode the text?
I want to array and function
Topic archived. No new replies allowed.