Thread: change text

  1. #16
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    You can use another switch, or just create tables:

    encode[] = {'a', 'b', 'c', 'd'};
    decode[] = {'l', 'j', 'g', 'w'};

    Instead of using switch statements, you just scan your tables until you hit the index you want and use the other table to encode/decode.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  2. #17
    Unregistered
    Guest
    Now that I know how to use a switch with this problem I would like to khow how to use tables such as:

    encode[] = {'a', 'b', 'c', 'd'};
    decode[] = {'l', 'j', 'g', 'w'};

    I want to be able to reverse what I encoded. A switch does not seem to be the way to do it since I don't think I can reverse a switch without rewriting the cases.....

    Any idea on how to proceed!!!!

    need the help badly!

  3. #18
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    You could always encode the test using an exclusive or statement though its not too secure unless every value you use to encode with is different, ie:
    Code:
    char password[10];
    char text[50];
    char newtext[50];
    int passlength;
    int passcounter;
    int textlength;
    int textcounter;
    
    
    // ASSIGN TEXT AND GET PASSWORD
    
    passlength=strlen(password);
    passcounter=0;
    textlength=strlen(text);
    textcounter=0;
    
    for(textcounter=0;textcounter<textlength;textcounter++,passwordcounter%=passlength)
      newtext[textcounter] = text[textcounter] ^ password[passwordcounter]
    
    newtext[textlength]='\0';
    only problem is it will encode every letter in the text, to decode the text just run the text through the program again, using the exact same password. I think the ^ is XOR, not 100% though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  2. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  3. change color text?
    By k4z1nh0 in forum C Programming
    Replies: 4
    Last Post: 03-15-2005, 11:41 AM
  4. help with calculating change from a dollar
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2002, 03:58 PM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM