The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Xor encryption
Discuss Xor encryption in the C Programming forum on Dev Shed. Xor encryption C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 2nd, 2003, 01:12 AM
|
|
Member
|
|
Join Date: Feb 2003
Location: Yerevan, Armenia
Posts: 224
Time spent in forums: 21 h 1 m 30 sec
Reputation Power: 11
|
|
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
|

March 2nd, 2003, 05:27 AM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
Quote: | 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.
|

March 2nd, 2003, 10:20 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
>> 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|