Thread: Character Tables ( Password Encryption )

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    183

    Character Tables ( Password Encryption )

    Hey peoples!

    Sorry, I'm back again. I realize that there was a recent thread about password encryption, so I do apologise for creating another. But I was reading that thread, and I read about a sort of "table of characters" method of encryption that I wanted to try. I understand the concept, but I don't know how it can be implemented. I started my function (well bool to be exact,) to simply take a string, go through it character by character, and based on the table, change it into it's designated symbol/number/letter. In my case, number. Then I intend to convert it to an int, and preform some mathematical calculations on it.

    How can this be achieved?
    Thanks for any future replies or any useful information you can provide.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So what's so hard about
    Code:
    struct foo {
      char clear;
      char cypher;
    } table[] = {
      { 'a', 'z' },
      { 'b', 'y' },
      { 'c', 'x' },
      // etc
    };
    Then having a for loop to match table[ i ].clear, and return table[ i ].cypher
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    183

    Unhappy Um ...

    Okay. I understood you until the table part. What does table[] mean? Where did table[ i ] come from? What's the difference between:
    Code:
     { 'a', 'z' }
    
     // and
    
     a = z ?
    Just F.Y.I. I'm a total noob.
    Sorry for my annoyingly persistant questions.

    EDIT:

    Oh, plus I do not know how to tell it to read one character at a time, so I don't know what condition to use in the loop.
    Last edited by Necrofear; 11-12-2006 at 11:46 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You get 'i' from a for loop, which examines each entry in the array which is called table.

    As in
    for ( i = 0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    183

    Arrays

    Never worked with arrays before. It says:
    Code:
     table[] undeclared (first use this function)
    How do I specify that it's an array?

    Cheers for the replies Salem.
    Last edited by Necrofear; 11-12-2006 at 12:28 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I showed you how to initialise the array.
    You need to post more code if it isn't working out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    183

    Ok. I got this so far:

    Code:
    #include <string>
    
    bool EncryptString ( string StringName )
    {
        struct Encryption_Variables
        {
            char clear;
            char cypher;
        }
        
        Table[] =
        {
            {'a', '162806'},
            {'b', '100615'},
            {'c', '62191'},
            {'d', '38424'},
            {'e', '23767'},
            {'f', '14657'},
            {'g', '9110'},
            {'h', '5547'},
            {'i', '3563'},
            {'j', '1984'},
            {'k', '1597'},
            {'l', '987'},
            {'m', '610'},
            {'n', '377'},
            {'o', '233'},
            {'p', '144'},
            {'q', '89'},
            {'r', '55'},
            {'s', '34'},
            {'t', '21'},
            {'u', '13'},
            {'v', '8'},
            {'w', '5'},
            {'x', '3'},
            {'y', '2'},
            {'z', '1'},
        };    
            
    }
    I get some errors saying: [Warning] character constant too long for its type.

    (26 to be exact. One for each letter.)

    I also get these: Line 3. `string' was not declared in this scope.

    And: Line 3. syntax error before `)' token.

    I understand the first error, but don't know how to fix it, and I don't understand the last two errors. Any help you could lend would be great. Cheers.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 'a', '162806'
    Why so many characters?
    Or are these really numbers?

    You have two choices
    1. make std::string cypher and have "162806"
    2. make int cypher and have 162806
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    make std::string cypher and have "162806"
    In this case the encoded strings should be also reconsidered...

    "13" cannot be uniquly decoded because it represents 2 possible sequences "u" or "zx", for example
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    the single quote ' is for a char

    ie 'a'

    your number in the single quote is that suposed to be char string or a number? like salems struct
    Code:
    struct foo {
      char clear;
      char cypher;
    } table[] = {
      { 'a', 'z' },
      { 'b', 'y' },
      { 'c', 'x' },
      // etc
    };
    one char for one place in the table[a] variable.
    if you want to use number you have to use int and not char unless you want a string "this is a string" note the double quotes that you would use in your struct.

    { "string1" , "string2" } .... and so on....

    edit
    what type of encryption?
    Last edited by kryptkat; 11-12-2006 at 03:13 PM.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Quote Originally Posted by Salem

    You have two choices
    1. make std::string cypher and have "162806"
    2. make int cypher and have 162806
    Apoligies for my incompetence, but I'm not sure I follow you. Basically, I want the function to read the first character into a string. Then I wish for it to look in the table (not literally, that would be hard to do,) for the number opposite it, and place that in another string. And then do the same with the rest of the characters.

    Also about the unique decoding flaw, would putting a period after each section of numbers help? So if the origional string was: Hello, the encoded string would look like this:

    5547.23767.987.987.233

    A bit like an IP address.
    Thanks again for replies!

    EDIT:

    What do you mean by: What type of encryption?
    Last edited by Necrofear; 11-12-2006 at 03:19 PM.

  12. #12
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Also about the unique decoding flaw, would putting a period after each section of numbers help?
    It would... But why to bother with the long strings in this case? There are 26 (or 255) literals in your encoded string that are easely determined by this points using the long enough encoded sequense... If you're going to provide this knolegde to the one trying to hack your mechanism why not just to go on the simple choice - one symbol is replaced by one symbol (as was suggested in the beggining)?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    > If you're going to provide this knolegde to the one trying to hack your mechanism why not just to go on the simple choice ect

    I didn't know I was going to provide this knowledge to the one trying to hack my mechanism. Why would I? Or am I already?

    Confused???

  14. #14
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I thought you're going to store the encrypted passwords somethere they can be easely (or not so easely) read? Why else you're bother to encript them?

    So someone looking on your list of encripted passwords and fingdings these intresting points inbetween your encripted letters can easely determine that actually only 26 different strings are present in the file... Or maybe its just my imagination...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  15. #15
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Oh I get you.

    Surely they won't be able determine how many strings are used if there are only say 7 sections of numbers in the file. If I gave you:

    610.233.377.1597.23767.2.34

    how would you know I was using thew first 26 terms of the fibonaci (sp?) sequence?
    Last edited by Necrofear; 11-12-2006 at 03:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. syntax error when defining vectors
    By starkhorn in forum C++ Programming
    Replies: 5
    Last Post: 09-22-2004, 12:46 PM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Character handling help
    By vandalay in forum C Programming
    Replies: 18
    Last Post: 03-29-2004, 05:32 PM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM