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

checksum works in unix but not win32 os

P: n/a
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.

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
[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
Tr****@ActiveState.com
Jul 18 '05 #2

P: n/a
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())


Did you make sure you opened this "fileobj" using
"rb" instead of the default "r"? Look for the
open() call that created it and put "rb" in... otherwise
CRLF combinations are converted to LF on input...

-Peter
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.