decoder

This is a discussion on decoder within the C++ Programming forums, part of the General Programming Boards category; Hey i got this assignment from my C++ class and I have no idea where to begin. we were given ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    decoder

    Hey i got this assignment from my C++ class and I have no idea where to begin.
    we were given some code to start out with & here are the instructions.
    any help is appreciated


    Your assignment is to decode a secret message. The message will be 26 characters in length, and will be given to you as a series of numbers. These numbers must be sorted and compared against a translation set of characters in order to decode it. This method is based upon the decoder rings that used to be available in packages of cereal.



    Perhaps the easiest way to show how to decode a message is to first show how a message is encoded. First, the letters of the alphabet, the numbers, and any punctuation is scrambled into some sort of sequence.



    For example, the string below can be found in codefile.txt:



    CFL2AP(T9W,H!JEM86ND0BZ7UK1Y3VG4XR)ISOQ5. ;-



    Notice that the above string contains 52 characters (including the nine blanks near the end). Now, let's suppose that we want to encode the message:



    HELP ME!



    Looking up each of the letters in the above string we find that H is the 11th character (zero-based indexing), E is the 14th, L the 2nd, P the 5th, one of the blanks the 41st, M the 15th, E the 14th, and ! the 12th. Therefore, our initial coding is:



    11 14 02 05 41 15 14 12



    Next, each number is assigned a three digit sequence number to precede it. These numbers indicate relative position, and need not be consecutive. For example, we might assign the following numbers:



    10111

    12214

    12802

    12905

    13541

    13715

    14214

    15112





    Finally, the order of the numbers is scrambled:



    13541

    12214

    10111

    15112

    13715

    12802

    14214

    12905



    This is the list of numbers you would be given to decode. To decode a message, simply reverse the process: read the numbers into an array and sort them into ascending order. "Cut" each sorted number into two, using the last two digits as the index to the correct character and print the character.



    For this lab the encoded message in numeric format is given below and can be found in: msgfile.txt:



    19546

    14501

    17309

    13027

    16149

    21512

    18035

    14014

    15700

    12515

    16514

    18207

    13407

    14837

    16842

    21037

    15333

    13244

    21224

    16321

    14146

    16014

    20727

    12804

    18811

    13711



    Given below is the main body of the program that you should use. For extra credit, pass the file names for this lab as command-line arguments.

    Code:
         int main(void) {
    
              char code[MAX];
    
              int msg[MAX];
    
              int msgSize;
    
     
    
              getCode(code);
    
              msgSize = getMessage(msg);
    
              sortMessage(msg, msgSize);
    
              decodeMessage(code, msg, msgSize);
    
              return 0;
    
         }
    Note that the string used to hold the 52 characters read from codefile.txt should be declared to be of length 53 (to reserve a space for the NULL character).



    Here is a function that will sort an integer array:

    Code:
    void sortMessage(int msg[], int msgSize) {
    
         int i, j, temp;
    
     
    
         for (i = 1; i < msgSize; i++) {
    
              temp = msg[i];
    
              j = i - 1;
    
              while (j >= 0 && temp < msg[j]) {
    
                   msg[j+1] = msg[j];
    
                   j = j - 1;
    
              }
    
              msg[j+1] = temp;
    
         }
    
    }

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,406
    Go away and do some work
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GIF Decoder (SZW Compression)
    By kapil1089thekin in forum C Programming
    Replies: 6
    Last Post: 05-15-2008, 01:48 AM
  2. MPEG 4 decoder
    By abachler in forum Windows Programming
    Replies: 11
    Last Post: 05-10-2007, 11:32 PM
  3. MP3 Decoder
    By Pete in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 05-02-2005, 08:35 AM
  4. ASCII Art Decoder and Encoder
    By jessweetd in forum C Programming
    Replies: 7
    Last Post: 09-05-2004, 07:12 PM
  5. Need RSA encoder / decoder / keygen
    By Rak'kar in forum Networking/Device Communication
    Replies: 4
    Last Post: 07-20-2004, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21