473,473 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

checksum works in unix but not win32 os

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
2 1581
[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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Peter Abel | last post by:
Hi all, I'm working under W2k with Python 2.2.2 (#37, Oct 14 2002, 17:02:34) on win32 I have a file *test_data.txt* with the following content: 0123456789 0123456789 abcdefghi...
2
by: GujuBoy | last post by:
is there a built-in function that does a "checksum" on a file...basicly counts the bytes and computes a 16-bit checksum for each given FILE. this is the like the "sum" command in unix
6
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
7
by: sea | last post by:
I understand that it is possible to test the integrity of data using something called checksum? What exactly is this and how do I use it in DB2? I've searched a lot of places but could not find an...
2
by: pradeep | last post by:
I have 2 data files, DATA1 and DATA2 , both same. My task is to: Open DATA1, compute the checksum and put it in the end of the file(don't bother about boundary conditions).close DATA1 Open...
4
by: Abby | last post by:
I have an array which contain Hex no. in each position. For examples, unsigned char data; data = 0x00; data = 0x01; data = 0x02; data = 0xE; data = 0xEF; --> This is the checksum value
6
by: Astroman | last post by:
Hi guys and girls. This is my first time posting here so go easy :) . I was wondering if someone could please interpret how this csum() function works in the following C code. I know that the...
24
by: Bob | last post by:
Hi there, I am working on an application to be used in our local Forensics department... Among other things the app will connect to a digital camera and download the images to the hard drive....
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.