checksum works in unix but not win32 os
Trent Mick
trentm at ActiveState.com
Tue Mar 29 21:10:40 EST 2005
[GujuBoy wrote]
> i have the following code...which works fine in UNIX but then i move it
> over to WINDOWS XP and check the sum on the same file that i tested on
> unix and i get different results.
>
> def checksum(fileobj):
> filedata = array.array('B', fileobj.read())
> totbytes = len(filedata)
> result = 0
> def rotate_right(c):
> if c&1: return (c>>1)|0x8000
> else: return c>>1
> for ch in filedata:
> result = (rotate_right(result)+ch) & 0xFFFF
> return result
>
> Unix File = 8683
> Win32 = 23662
>
> Please let me know why its acting different in WIN32, also it only does
> this on SOME files...out of 50 i tested only 5 it failed on.
By "failed" you mean the checksum is different? The file itself (if it
is a text file) might very well have different content: EOL characters
are different on Windows (CRLF) and Unix (LF). If a text file is opened
in textmode (the default), then the CRLF's will get translated to LF's,
however, if opened in binary mode (by having a 'b' in the mode option to
open()/file()) then this translation is not done.
Also, any reason you are not just using the hexdigest() method in the
md5 module?
Cheers,
Trent
--
Trent Mick
TrentM at ActiveState.com
More information about the Python-list
mailing list