By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

crypt() and md5()

P: n/a
I'm curious how these two functions work together (when crypt() uses a md5
algo). Currently I know they will produce different output; is this due to
the salt being used behind-the-scenes in md5()? Is there a way to allow
crypt() and md5() to produce identical output or am I misunderstanding the
purpose of both the functions.

Thanks
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* <ba***@blues.no>:
I'm curious how these two functions work together (when crypt() uses a
md5 algo).
When crypt() "uses a MD5 algorithm", I'm assuming that that means that the
algorithm used by crypt() is similar to the one used by md5(). It *does
not* mean, however, that the output of crypt() will be an MD5 sum.
Currently I know they will produce different output; is this due to the
salt being used behind-the-scenes in md5()?
If you have a function foo() that produces an MD5 sum, and another
function bar() that also produces an MD5 sum, the value of foo(string)
will /always/ be the same as the value of bar(string) -- in other words,
any given string has exactly one MD5 sum. (The converse is also almost
always true: any given MD5 sum can be produced by only one string.
Coincidentally, this is why MD5 is used for file verification and the
like.)

What this means is that if crypt() and md5() give different outputs, then
you know that one of them is not intended to generate MD5 sums. In this
case, that one is crypt().
Is there a way to allow crypt() and md5() to produce identical output or
am I misunderstanding the purpose of both the functions.


I think you're misunderstanding it -- the purpose of crypt() is produce an
encrypted string with a given salt. The implementations of crypt() will
vary from system to system, as different systems implement it differently.
Therefore, the output of crypt() varies with different systems and salts.

MD5, on the other hand, is more of a universal algorithm -- the md5()
function on my computer will always give the same results as the md5()
function on your computer. The MD5 sum of a given string /doesn't vary/.

To answer your original question (sorry for the rambling) -- there is not,
AFAIK, any way to make crypt() output MD5 sums. You should use md5() for
that.

HTH,
--
Benjamin D. Esham { http://bdesham.net
bd*****@iname.com } AIM: bdesham 1 2 8
"Hmm... Earl Grey tea. Maybe that's how an old
bald guy can kick the Borg's collective ass."

Jul 16 '05 #2

P: n/a
Thanks for those wonderful ramblings. They *were* helpful.
Jul 16 '05 #3

P: n/a
Benjamin Esham <bd*****@iname.com> writes:
any given string has exactly one MD5 sum. (The converse is also almost
always true: any given MD5 sum can be produced by only one string.


More precisely, with 16^32 different MD5 sums, the chances of two
different strings giving the same one can be discounted. Combining
with strlen() cuts that chance down even further, at least until you
start using string of the order of 16^32 in length.

--
Chris
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.