Thread: Xor encryption

    #1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Yerevan, Armenia
    Posts
    224
    Rep Power
    12

    Question Xor encryption


    Ok, I've been writing a XOR encryption algorythm and I stumbled on a problem here. I need the key to be 64 bits, i know long int is 64 bits, however I want the user to input a string which will then be used as a key. How do I turn a string into long int and how do I make sure my string is not more than 64 bits?

    Thanks for any help
    -Nar
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    i know long int is 64 bits,
    this is wrong. afaik a "long" is "at least 32 bits". So it depends on your compiler / OS if it is exactly or more than 32bits. There should be a type "Int64", "INT64" or similar (not portable!) that always has 64 bits.

    for making a string of a long int:

    - the string has to be at least 8 characters (ASCII). you cannot make a 64 bits keys if the user only enters 32 bits.

    - to make strings that are at least 64bits become a key of exactly 64bits, you need some kind of hashing algorithm. eg. like using two times CRC32 for each half of the string. the resulting hash is then used to encrypt your data.
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    >> i know long int is 64 bits
    The ANSI standard for C (and as far as I know, C++ as well) only says that "the only restriction on the size of long is that it cannot be shorter than the int type". Currently on a 32-bit gcc compiler, both int and long are 32 bits in size. On the 64-bit version, int is 32 bits, but long is 64 bits. On most 16-bit DOS compilers, int was 16 bits and long was 32 bits. gcc does define a type called long long int (long long types were introduced into the C99 standard for C. Note that they are not part of the current ISO C++ standard though). For gcc, long long int is 64 bits on a 32-bit compiler. Other compilers declare int_64, Int64 etc. depending upon your compiler. As M. Hirsch pointed out above, using any of these makes your code non-portable to other compilers (if you care about it, that is). However, if you're only targetting a single compiler, then you could use whatever 64 bit type that your compiler provides.

    Just out of curiosity, why does the key need to be exactly 64 bits in length for a XOR encryption? Are you just XORing each character in the plain text against the key. If this is the case, why don't you just use whatever key is inputted and XOR each character of your plaintext against each character in the key and cycle the key when you get to the end?

    Hope this helps! :)
    Last edited by Scorpions4ever; March 2nd, 2003 at 10:23 AM.

IMN logo majestic logo threadwatch logo seochat tools logo