Plz Help!!!

This is a discussion on Plz Help!!! within the C++ Programming forums, part of the General Programming Boards category; OK, I have been stuck on this one for weeks: I am trying to develope my own encrypter of text. ...

  1. #1
    Registered User Machewy's Avatar
    Join Date
    Apr 2003
    Posts
    42

    Exclamation Plz Help!!!

    OK,
    I have been stuck on this one for weeks:
    I am trying to develope my own encrypter of text.
    What I need is just a few examples of how to do this.
    For example how would I do this in C++?
    Code:
    'a' = 'b'
    'b' = 't'
    /n = 'y'
    etc.......
    I want the user to be able to type in the text and have it encrypted.
    best regards,
    machewy
    Last edited by Machewy; 04-16-2003 at 09:02 AM.
    "All things come to an end"

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    I don't think you can do that.

    You can enter as a string, parse it, replace certain letters with others.

  3. #3
    Registered User Machewy's Avatar
    Join Date
    Apr 2003
    Posts
    42
    How would I do that???
    "All things come to an end"

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    String parse's and such have been covered many times before, a little research may prove to be all you need.

  5. #5
    Registered User zerodevide's Avatar
    Join Date
    Apr 2003
    Posts
    6

    use an array

    You're doing a simple substitution cypher - been around for well over a thousand years.

    Create an array with the translation - make it as big as an ascii table. Create a loop to read in the input, convert to an ascii interger, and pull that from the char array you've set up.

    additonally build a string from the translation and then you can write it to the screen or a file.

    Translation back would work the same way - convert the chars into ascii values and use another array to pull the original characters back.

    i.e 0 = 48 = j
    j = 106 = 0

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Use a 2d array.

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I assume you know all about ASCII, and have an ASCII chart.

    So, you need 3 arrays:
    OrigString[]
    EncString[]
    Convert[]

    The original character becomes a pointer (or index value) for the convert array.

    From your example:
    a = 97
    b = 98
    t = 116

    And we know,
    Convert[97] = 98 (97 points to 98)
    Convert[98] = 116 (98 points to 116)
    ... You fill-in the rest.

    In general,
    EncString[n] = Convert[ OrigString[n] ]

    been around for well over a thousand years.
    Yeah, but they've only been doing it in C++ for about 100 years!

  8. #8
    Registered User Machewy's Avatar
    Join Date
    Apr 2003
    Posts
    42

    Unhappy

    I'm still confused.
    I got this far:
    PHP Code:
    #include <iostream.h>
    #include <stdlib.h>

    int main()
    {
     
    char OrigString[100];
     
    char EncString[100];
     
    char Convert[100];

     
    Convert[97] = 98;
     
    cin.getline(Convert100);
     
    cout<<Convert;

     
    system("PAUSE");
     return 
    0;

    What should I do???
    Can someone write me up a quick example program to use as a reference?
    Thanks
    "All things come to an end"

  9. #9
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    look at http://www.asciitable.com/ as you can see here ever single character has a numeric value attached to it. Now what you do it you take one character and you convert it to it's ascii value:

    Code:
    char x = '\0';
    int ascii = 0;
    
    cin.get(x);
    
    ascii = (int)x;
    so now ascii holds the numerical value for the character x. Second you need a 2d array that has first the ascii value of the first/original character as it's index and then the ascii value of the encoded character:

    Code:
    int Table[256] = { 35,
                                 67,
                                 ........
                                 79 };
    Please note that the encoded and original values were picked at random by me =].

    Now following the above code given when you do something alike:

    Code:
    char encoded = (char)Table[ascii];
    To decypher your code you can either build a new array that would have 1 stored in it's 35th element (following the above example) or you could have a for loop that goes through the original array and finds the encoded value and then uses the index as the decyphered value:

    Code:
    int Decode[256] = { ......
                                     1,   // 35th element
                                     ......
                                     2,  // 67th element
                                     ......
                                     256, // 79th element
                                     ...... };
    
    char original = (char)Decode[ (int)encoded ];
    -or-

    Code:
    for(int i = 0; Table[i] != (int)encoded; i++)
    {}
    
    char original = (char)i;
    note that the first example with a new array takes more memory and that the second example with the for loop takes more CPU time. So it is up to you to decide which you value more...

  10. #10
    Registered User Machewy's Avatar
    Join Date
    Apr 2003
    Posts
    42
    Thanks so much!!!!!!

    The only thing I am going to have to do now is play around with what you guys gave me.
    Anymore suggestions?
    "All things come to an end"

  11. #11
    Xei
    Xei is offline
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    Originally posted by Machewy
    Thanks so much!!!!!!

    The only thing I am going to have to do now is play around with what you guys gave me.
    Anymore suggestions?
    Yes. Look up XOR, it may interest you.
    "What are you after - the vague post of the week award?" - Salem
    IPv6 Ready.
    Travel the world, meet interesting people...kill them.
    Trying to fix or change something, only guaruntees and perpetuates its existence.
    I don't know about angels, but it is fear that gives men wings.
    The problem with wanting something is the fear of losing it, or never having it. The thought makes you weak.

    E-Mail Xei

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 10:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

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