Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86707
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Windows': 0.02; 'binary': 0.07; 'computed': 0.09; 'data:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:2 30': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; '"\\r\\n"': 0.16; 'hashlib': 0.16; 'md5': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'true:': 0.16; 'unchanged': 0.16; 'wrote:': 0.18; 'translated': 0.19; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'passes': 0.24; 'skip:e 30': 0.24; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'thus': 0.29; 'mode': 0.30; 'linux.': 0.31; 'file': 0.32; 'run': 0.32; 'open': 0.33; 'linux': 0.33; 'but': 0.35; 'there': 0.35; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'break': 0.61; 'different': 0.65; 'amazed': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Md5 is different in Windows and Linux |
| Date | Mon, 02 Mar 2015 09:54:13 +0100 |
| Organization | None |
| References | <CA+QVAb4D1JTnaQ5ZOaB51syt1_NePt+QeSHOxEmnhMjxr10BEQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd913e.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19.1425286466.13471.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425286466 news.xs4all.nl 2965 [2001:888:2000:d::a6]:38003 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86707 |
Show key headers only | View raw
Sarvagya Pant wrote:
> 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.?
You have to open the file in binary mode
f = open("somefile.txt", "rb")
Otherwise on Windows "\r\n" will be translated to "\n" while Linux passes
the bytes unchanged -- and thus md5.update() will see different data and
produce a different checksum.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Md5 is different in Windows and Linux Peter Otten <__peter__@web.de> - 2015-03-02 09:54 +0100
csiph-web