|
 |
|
 |
05-10-2004, 06:53 PM
|
#1 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
Crypt program choking - need help.
-------------------------------------------------------------------------
I need some advise on crypt.
Last edited by liguorir; 05-23-2004 at 04:30 PM.
|
|
|
05-10-2004, 07:01 PM
|
#2 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,161
|
Sorry, I'm not enough of an expert to debug your problem, but I would like to ask another question. Why are you using crypt instead of something like md5?
|
|
|
05-10-2004, 07:13 PM
|
#3 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
-lcrypt
Thanks for the help.
Last edited by liguorir; 05-23-2004 at 04:30 PM.
|
|
|
05-10-2004, 07:23 PM
|
#4 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,161
|
crypt is an old one-way encryption algorithmn. MD5 is suppose to be superior, fewer collisions and what not. I see it used a lot more often than crypt now adays.
|
|
|
05-23-2004, 01:02 AM
|
#5 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
All spiced up
I got it, thanks!
Last edited by liguorir; 05-23-2004 at 04:32 PM.
|
|
|
05-23-2004, 03:12 AM
|
#6 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
Re: All spiced up
Quote:
Originally posted by liguorir
Code:
// Determines random range to use
int range = ( 1+(int) (3.0*rand()/(RAND_MAX+1.0)) );
|
what is this nonsense? if you're trying to generate a number between 1 and 3, this is a terrible way to do it. try this instead:
Code:
int range = 1 + (rand() % 3);
|
|
|
05-23-2004, 03:37 PM
|
#7 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
It's not nonsense.
But your solution does sound good to me!
Thanks.
Last edited by liguorir; 05-23-2004 at 04:32 PM.
|
|
|
05-23-2004, 04:02 PM
|
#8 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
that is ancient history, and does not hold true for any modern system. man rand sayeth:
Code:
NOTES
The versions of rand() and srand() in the Linux C Library
use the same random number generator as random() and sran_
dom(), so the lower-order bits should be as random as the
higher-order bits. However, on older rand() implementa_
tions, the lower-order bits are much less random than the
higher-order bits.
In Numerical Recipes in C: The Art of Scientific Computing
(William H. Press, Brian P. Flannery, Saul A. Teukolsky,
William T. Vetterling; New York: Cambridge University
Press, 1992 (2nd ed., p. 277)), the following comments are
made:
"If you want to generate a random integer between 1
and 10, you should always do it by using high-order
bits, as in
j=1+(int) (10.0*rand()/(RAND_MAX+1.0));
and never by anything resembling
j=1+(rand() % 10);
(which uses lower-order bits)."
besides, if you were worried about real random values, you would use the entropy gathering random device or a real random number generator (like those found on most processors) instead of rand(), and you would not have an implemetation that seems to favor numbers (one out of 3 values for your seed will be a number, even though numbers make up only 16% of the textspace).
|
|
|
05-23-2004, 04:13 PM
|
#9 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
Thanks Joe.
Joe,
Thanks for the advise.
Do you know the complete range of valid characters for salt/crypt?
I haven't been able to find it.
|
|
|
05-23-2004, 04:46 PM
|
#10 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
salt is a two-character string chosen from the set [a-zA-Z0-9./].
my point was that picking 1-3(upper, lower, or digit) and then picking the character/digit, gives you a 1 in 3 chance that you'll pick a digit (while there are 52 characters and only 10 digits).
|
|
|
05-23-2004, 04:56 PM
|
#11 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
Thanks again, and yet another question.
I see now thanks,
Another question...
What are the values for ./ ( or is there an extended range? )
Note: http://www.asciitable.com/
Is it just 46 and 47?
And what do you advise to implement to have an equally distributed random production of valid characters?
Thanks,
Robert
|
|
|
05-23-2004, 05:33 PM
|
#12 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
Code:
char *values = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./"
mod = strlen(values);
for(i = 0; i < 2: i++) salt[i] = values[rand() % mod];
for some reason this message board decided to insert a space between my the quote and the value zero in the first line, and i can't seem to get rid of it. it should not be there.
|
|
|
05-23-2004, 05:49 PM
|
#13 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
Compilation errors
Got it.
|
|
|
05-23-2004, 05:57 PM
|
#14 (permalink)
|
|
Registered User
Join Date: May 2004
Posts: 12
|
Works great.
Works great... thank!
|
|
|
| Thread Tools |
|
|
| Display Modes |
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
|
|
|
All times are GMT -8. The time now is 07:02 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|