Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-10-2004, 06:53 PM   #1 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
Question Crypt program choking - need help.

-------------------------------------------------------------------------
I need some advise on crypt.

Last edited by liguorir; 05-23-2004 at 04:30 PM.
liguorir is offline   Reply With Quote
Old 05-10-2004, 07:01 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
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?
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-10-2004, 07:13 PM   #3 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
-lcrypt

Thanks for the help.

Last edited by liguorir; 05-23-2004 at 04:30 PM.
liguorir is offline   Reply With Quote
Old 05-10-2004, 07:23 PM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
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.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-23-2004, 01:02 AM   #5 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
Cool All spiced up

I got it, thanks!

Last edited by liguorir; 05-23-2004 at 04:32 PM.
liguorir is offline   Reply With Quote
Old 05-23-2004, 03:12 AM   #6 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
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);
joe_bruin is offline   Reply With Quote
Old 05-23-2004, 03:37 PM   #7 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
Cool It's not nonsense.

But your solution does sound good to me!

Thanks.

Last edited by liguorir; 05-23-2004 at 04:32 PM.
liguorir is offline   Reply With Quote
Old 05-23-2004, 04:02 PM   #8 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
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).
joe_bruin is offline   Reply With Quote
Old 05-23-2004, 04:13 PM   #9 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
Question 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.
liguorir is offline   Reply With Quote
Old 05-23-2004, 04:46 PM   #10 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
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).
joe_bruin is offline   Reply With Quote
Old 05-23-2004, 04:56 PM   #11 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
Question 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
liguorir is offline   Reply With Quote
Old 05-23-2004, 05:33 PM   #12 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
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.
joe_bruin is offline   Reply With Quote
Old 05-23-2004, 05:49 PM   #13 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
Question Compilation errors

Got it.
liguorir is offline   Reply With Quote
Old 05-23-2004, 05:57 PM   #14 (permalink)
liguorir
Registered User
 
Join Date: May 2004
Posts: 12
liguorir is on a distinguished road
Works great.

Works great... thank!
liguorir is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Help on starting new program B00tleg Standard C, C++ 21 10-17-2004 12:58 PM
Need help on program B00tleg Standard C, C++ 1 10-12-2004 12:02 AM
Help on interest program B00tleg Standard C, C++ 2 10-07-2004 08:50 PM


All times are GMT -8. The time now is 07:02 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting