C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 2nd, 2003, 01:12 AM
Narek Narek is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Yerevan, Armenia
Posts: 224 Narek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 1 m 30 sec
Reputation Power: 6
Send a message via ICQ to Narek
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

Reply With Quote
  #2  
Old March 2nd, 2003, 05:27 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 184
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.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old March 2nd, 2003, 10:20 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,589 Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 40 m 58 sec
Reputation Power: 1001
>> 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Xor encryption


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT