Is md5 broken in Jython?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Is md5 broken in Jython?

Leo User
Hi,
 
I noticed some capitalisation differences in the output from md5 in jython and python.  I don't know if its broken, but Im assuming that it is.
A Jython session:
Jython 2.2a1 on java1.5.0_02 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import md5
>>> a = md5.new()
>>> a.digest()
'\xD4\x1D\x8C\xD9\x8F\x00\xB2\x04\xE9\x80\t\x98\xEC\xF8B~'
>>> a.update( "CAT" )
>>> a.digest()
'\xC0\x1A\xE1\xA5\xF1"\xF2\\\xE5g_\x86\x02\x8BSj'
>>>

A Python session:
C:\WINDOWS>python
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import md5
>>> a = md5.new()
>>> a.digest()
'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~'
>>> a.update( "CAT" )
>>> a.digest()
'\xc0\x1a\xe1\xa5\xf1"\xf2\\\xe5g_\x86\x02\x8bSj'
>>>
 
--------
notice how the digest returns the same letters but in some cases the capitalisation is different.  Im assuming this is a bug, but maybe it is OK for md5 to do this... thought I find the chances of that being correct slim.
 
leouser
 

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: Is md5 broken in Jython?

Jeff Emanuel
The 2 characters following \x are hexidecimal digits.  Case
doesn't matter.

Leo User wrote:

> Hi,
>  
> I noticed some capitalisation differences in the output from md5 in jython and python.  I don't know if its broken, but Im assuming that it is.
> A Jython session:
> Jython 2.2a1 on java1.5.0_02 (JIT: null)
> Type "copyright", "credits" or "license" for more information.
>
>>>>import md5
>>>>a = md5.new()
>>>>a.digest()
>
> '\xD4\x1D\x8C\xD9\x8F\x00\xB2\x04\xE9\x80\t\x98\xEC\xF8B~'
>
>>>>a.update( "CAT" )
>>>>a.digest()
>
> '\xC0\x1A\xE1\xA5\xF1"\xF2\\\xE5g_\x86\x02\x8BSj'
>
>
> A Python session:
> C:\WINDOWS>python
> Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>>import md5
>>>>a = md5.new()
>>>>a.digest()
>
> '\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~'
>
>>>>a.update( "CAT" )
>>>>a.digest()
>
> '\xc0\x1a\xe1\xa5\xf1"\xf2\\\xe5g_\x86\x02\x8bSj'
>
>  
> --------
> notice how the digest returns the same letters but in some cases the capitalisation is different.  Im assuming this is a bug, but maybe it is OK for md5 to do this... thought I find the chances of that being correct slim.
>  
> leouser
>  
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com 


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev
Reply | Threaded
Open this post in threaded view
|

Re: Is md5 broken in Jython?

Kent Johnson
In reply to this post by Leo User
Leo User wrote:

> Hi,
>  
> I noticed some capitalisation differences in the output from md5 in
> jython and python.  I don't know if its broken, but Im assuming that it is.
> A Jython session:
> Jython 2.2a1 on java1.5.0_02 (JIT: null)
>  >>> a.digest()
> '\xC0\x1A\xE1\xA5\xF1"\xF2\\\xE5g_\x86\x02\x8BSj'
>  >>>
>
> A Python session:
> C:\WINDOWS>python
> Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
> win32
>  >>> a.digest()
> '\xc0\x1a\xe1\xa5\xf1"\xf2\\\xe5g_\x86\x02\x8bSj'
>  >>>
>  
> --------
> notice how the digest returns the same letters but in some cases the
> capitalisation is different.

This is just a difference in the repr() of the string - the letters are hex digits in \x escapes, not actually part of the hash itself. A plain string shows the same difference:
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> '\xab'
'\xab'
 >>> ^Z

Jython 2.2a1 on java1.4.2_06 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> '\xab'
'\xAB'

Arguably this is a bug in str.__repr__() but it is not a problem with the hash algorithm.

Kent



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev
Reply | Threaded
Open this post in threaded view
|

Re: Is md5 broken in Jython?

Leo User
this is most interesting.  The real test for me is going to be whether or not the digest created in jython and stashed is going to be == to one created by python.  We may be using md5 to test whether data has changed, and it needs to work in both environments.  I somewhat suspect that it might given your comments here.
 
thanks!
leouser

Kent Johnson <[hidden email]> wrote:
Leo User wrote:

> Hi,
>
> I noticed some capitalisation differences in the output from md5 in
> jython and python. I don't know if its broken, but Im assuming that it is.
> A Jython session:
> Jython 2.2a1 on java1.5.0_02 (JIT: null)
> >>> a.digest()
> '\xC0\x1A\xE1\xA5\xF1"\xF2\\\xE5g_\x86\x02\x8BSj'
> >>>
>
> A Python session:
> C:\WINDOWS>python
> Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
> win32
> >>> a.digest()
> '\xc0\x1a\xe1\xa5\xf1"\xf2\\\xe5g_\x86\x02\x8bSj'
> >>>
>
> --------
> notice how the digest returns the same letters but in some cases the
> capitalisation is different.

This is just a difference in the repr() of the string - the letters are hex digits in \x escapes, not actually part of the hash itself. A plain string shows the same difference:
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> '\xab'
'\xab'
>>> ^Z

Jython 2.2a1 on java1.4.2_06 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> '\xab'
'\xAB'

Arguably this is a bug in str.__repr__() but it is not a problem with the hash algorithm.

Kent



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com