Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Windows': 0.02; 'computed': 0.09; 'data:': 0.09; 'skip:2 30': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; 'hashlib': 0.16; 'md5': 0.16; 'true:': 0.16; 'filename:fname piece:txt': 0.16; 'import': 0.22; 'print': 0.22; 'skip:e 30': 0.24; 'code:': 0.26; 'message- id:@mail.gmail.com': 0.30; 'linux.': 0.31; 'file': 0.32; 'run': 0.32; 'linux': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:\xc2 10': 0.60; 'break': 0.61; 'skip:o 30': 0.61; 'different': 0.65; '8bit%:100': 0.72; 'amazed': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=sxAifCchxR5w8HUSmmpKIUMkKLk1zMm+RSs5pZYHXu0=; b=Jd0t5ql/Ej6d4xauQT3RUyH6w8lb9+JgE6T6oG/vBJjdU2ZTQxlEDIKeL8SI2ztxkm NjKK2tQKGVVR3oelhRmfV+ZiRZK7VJU7Mz63nulz+bqFHdwodQiBj2LU4cVYh0Iqgg+h ypxjAiYukoY6G8BDawDKsf8sqVjY/irn0unFJrwKATEEE1nILuW8bv1bk4Zt/gLSpZCk Iik9Mr2UGqWvaqD01xmohOZJEzjkydNcr+vVnH/lDZQ4qcH5dMVDreLFERu+RaTwN4Vb 1qnuFlEbdDdk29O6BARXTglPu5beMrkTSSRhwH5wx9HBFqn69nA1uB2HvnsAvSbQRhAU wubw== MIME-Version: 1.0 X-Received: by 10.112.201.69 with SMTP id jy5mr8361020lbc.78.1425277186818; Sun, 01 Mar 2015 22:19:46 -0800 (PST) Date: Mon, 2 Mar 2015 12:04:46 +0545 Subject: Md5 is different in Windows and Linux From: Sarvagya Pant To: python-list@python.org Content-Type: multipart/mixed; boundary=001a11c373546d6c01051048344b X-Mailman-Approved-At: Mon, 02 Mar 2015 09:43:47 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425285828 news.xs4all.nl 2862 [2001:888:2000:d::a6]:53043 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86703 --001a11c373546d6c01051048344b Content-Type: multipart/alternative; boundary=001a11c373546d6bfb0510483449 --001a11c373546d6bfb0510483449 Content-Type: text/plain; charset=UTF-8 Hello, I am amazed that the md5 of a file given by python in windows is different than that of linux. Consider the following code: import hashlib def md5_for_file(f, block_size=2**20): md5 = hashlib.md5() while True: data = f.read(block_size) if not data: break md5.update(data) return md5.hexdigest() f = open("somefile.txt") print md5_for_file(f) When I run the program I get the checksum value: 2f9cc8da53ee89762a34702f745d2956 But on this site http://onlinemd5.com/ and on linux it has value E10D4E3847713472F51BC606852712F1. Why is there difference in value of Checksum computed by python in windows and other system.? -- *sarvagya* --001a11c373546d6bfb0510483449 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello, I am amazed that the=C2=A0 md5 of a file given by = python in windows is different than that of linux. Consider the following c= ode:

import hashlib
def md5_for_file(f, block_size=3D2**20):
= =C2=A0=C2=A0=C2=A0 md5 =3D hashlib.md5()
=C2=A0=C2=A0=C2=A0 while True:<= br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 data =3D f.read(block_size)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if not data:
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 md5.update(data)
=C2=A0=C2=A0=C2=A0 re= turn md5.hexdigest()

f =3D open("somefile.txt")
print m= d5_for_file(f)

When I run the program I get the checksum valu= e: 2f9cc8da53ee89762a34702f745d2956

But on this site http://onlinemd5.com/ and on linux it has value E10D= 4E3847713472F51BC606852712F1.

Why is there difference in valu= e of Checksum computed by python in windows and other system.?

--
sarvagya
--001a11c373546d6bfb0510483449-- --001a11c373546d6c01051048344b Content-Type: text/plain; charset=US-ASCII; name="somefile.txt" Content-Disposition: attachment; filename="somefile.txt" Content-Transfer-Encoding: base64 X-Attachment-Id: f_i6rh67sv0 SGVsbG8NCkNoZWNrIHRoZSBNRDUNCm9mIHRoaXMgZmlsZQ== --001a11c373546d6c01051048344b--