<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Md5.py</id>
	<title>Md5.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Md5.py"/>
	<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Md5.py&amp;action=history"/>
	<updated>2026-05-18T12:43:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1563&amp;oldid=prev</id>
		<title>PeterHarding at 02:58, 29 February 2008</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1563&amp;oldid=prev"/>
		<updated>2008-02-29T02:58:30Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:58, 29 February 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l3&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__TOC__&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__TOC__&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;http://www.performiq.com.au/kb/images/Md5py.pdf&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* &lt;/ins&gt;http://www.performiq.com.au/kb/images/Md5py&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.pdf&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* http://www.performiq.com.au/kb/images/Test_MD5py&lt;/ins&gt;.pdf&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Script=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Script=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1561&amp;oldid=prev</id>
		<title>PeterHarding at 02:57, 29 February 2008</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1561&amp;oldid=prev"/>
		<updated>2008-02-29T02:57:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://performiq.com/kb/index.php?title=Md5.py&amp;amp;diff=1561&amp;amp;oldid=1560&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1560&amp;oldid=prev</id>
		<title>PeterHarding at 02:56, 29 February 2008</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1560&amp;oldid=prev"/>
		<updated>2008-02-29T02:56:05Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:56, 29 February 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=Documentation=&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;http://www.performiq.com.au/kb/images/Md5py.pdf&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Script=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Script=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1558&amp;oldid=prev</id>
		<title>PeterHarding: New page: =Script=  &lt;pre&gt; #!/usr/bin/env python  &quot;&quot;&quot;A sample implementation of MD5 in pure Python.  This is an implementation of the MD5 hash function, as specified by RFC 1321, in pure Python. It w...</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Md5.py&amp;diff=1558&amp;oldid=prev"/>
		<updated>2008-02-29T02:55:28Z</updated>

		<summary type="html">&lt;p&gt;New page: =Script=  &amp;lt;pre&amp;gt; #!/usr/bin/env python  &amp;quot;&amp;quot;&amp;quot;A sample implementation of MD5 in pure Python.  This is an implementation of the MD5 hash function, as specified by RFC 1321, in pure Python. It w...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Script=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;A sample implementation of MD5 in pure Python.&lt;br /&gt;
&lt;br /&gt;
This is an implementation of the MD5 hash function, as specified by&lt;br /&gt;
RFC 1321, in pure Python. It was implemented using Bruce Schneier&amp;#039;s&lt;br /&gt;
excellent book &amp;quot;Applied Cryptography&amp;quot;, 2nd ed., 1996.&lt;br /&gt;
&lt;br /&gt;
Surely this is not meant to compete with the existing implementation&lt;br /&gt;
of the Python standard library (written in C). Rather, it should be&lt;br /&gt;
seen as a Python complement that is more readable than C and can be&lt;br /&gt;
used more conveniently for learning and experimenting purposes in&lt;br /&gt;
the field of cryptography.&lt;br /&gt;
&lt;br /&gt;
This module tries very hard to follow the API of the existing Python&lt;br /&gt;
standard library&amp;#039;s &amp;quot;md5&amp;quot; module, but although it seems to work fine,&lt;br /&gt;
it has not been extensively tested! (But note that there is a test&lt;br /&gt;
module, test_md5py.py, that compares this Python implementation with&lt;br /&gt;
the C one of the Python standard library.&lt;br /&gt;
&lt;br /&gt;
BEWARE: this comes with no guarantee whatsoever about fitness and/or&lt;br /&gt;
other properties! Specifically, do not use this in any production&lt;br /&gt;
code! License is Python License!&lt;br /&gt;
&lt;br /&gt;
Special thanks to Aurelian Coman who fixed some nasty bugs!&lt;br /&gt;
&lt;br /&gt;
Dinu C. Gherman&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__date__    = &amp;#039;2001-10-1&amp;#039;&lt;br /&gt;
__version__ = 0.9&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
import struct, string, copy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ======================================================================&lt;br /&gt;
# Bit-Manipulation helpers&lt;br /&gt;
#&lt;br /&gt;
#   _long2bytes() was contributed by Barry Warsaw&lt;br /&gt;
#   and is reused here with tiny modifications.&lt;br /&gt;
# ======================================================================&lt;br /&gt;
&lt;br /&gt;
def _long2bytes(n, blocksize=0):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Convert a long integer to a byte string.&lt;br /&gt;
&lt;br /&gt;
    If optional blocksize is given and greater than zero, pad the front&lt;br /&gt;
    of the byte string with binary zeros so that the length is a multiple&lt;br /&gt;
    of blocksize.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    # After much testing, this algorithm was deemed to be the fastest.&lt;br /&gt;
    s = &amp;#039;&amp;#039;&lt;br /&gt;
    pack = struct.pack&lt;br /&gt;
    while n &amp;gt; 0:&lt;br /&gt;
        ### CHANGED FROM &amp;#039;&amp;gt;I&amp;#039; TO &amp;#039;&amp;lt;I&amp;#039;. (DCG)&lt;br /&gt;
        s = pack(&amp;#039;&amp;lt;I&amp;#039;, n &amp;amp; 0xffffffffL) + s&lt;br /&gt;
        ### --------------------------&lt;br /&gt;
        n = n &amp;gt;&amp;gt; 32&lt;br /&gt;
&lt;br /&gt;
    # Strip off leading zeros.&lt;br /&gt;
    for i in range(len(s)):&lt;br /&gt;
        if s[i] &amp;lt;&amp;gt; &amp;#039;\000&amp;#039;:&lt;br /&gt;
            break&lt;br /&gt;
    else:&lt;br /&gt;
        # Only happens when n == 0.&lt;br /&gt;
        s = &amp;#039;\000&amp;#039;&lt;br /&gt;
        i = 0&lt;br /&gt;
&lt;br /&gt;
    s = s[i:]&lt;br /&gt;
&lt;br /&gt;
    # Add back some pad bytes. This could be done more efficiently&lt;br /&gt;
    # w.r.t. the de-padding being done above, but sigh...&lt;br /&gt;
    if blocksize &amp;gt; 0 and len(s) % blocksize:&lt;br /&gt;
        s = (blocksize - len(s) % blocksize) * &amp;#039;\000&amp;#039; + s&lt;br /&gt;
&lt;br /&gt;
    return s&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _bytelist2long(list):&lt;br /&gt;
    &amp;quot;Transform a list of characters into a list of longs.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    imax = len(list)/4&lt;br /&gt;
    hl = [0L] * imax&lt;br /&gt;
&lt;br /&gt;
    j = 0&lt;br /&gt;
    i = 0&lt;br /&gt;
    while i &amp;lt; imax:&lt;br /&gt;
        b0 = long(ord(list[j]))&lt;br /&gt;
        b1 = (long(ord(list[j+1]))) &amp;lt;&amp;lt; 8&lt;br /&gt;
        b2 = (long(ord(list[j+2]))) &amp;lt;&amp;lt; 16&lt;br /&gt;
        b3 = (long(ord(list[j+3]))) &amp;lt;&amp;lt; 24&lt;br /&gt;
        hl[i] = b0 | b1 |b2 | b3&lt;br /&gt;
        i = i+1&lt;br /&gt;
        j = j+4&lt;br /&gt;
&lt;br /&gt;
    return hl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _rotateLeft(x, n):&lt;br /&gt;
    &amp;quot;Rotate x (32 bit) left n bits circularly.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    return (x &amp;lt;&amp;lt; n) | (x &amp;gt;&amp;gt; (32-n))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ======================================================================&lt;br /&gt;
# The real MD5 meat...&lt;br /&gt;
#&lt;br /&gt;
#   Implemented after &amp;quot;Applied Cryptography&amp;quot;, 2nd ed., 1996,&lt;br /&gt;
#   pp. 436-441 by Bruce Schneier.&lt;br /&gt;
# ======================================================================&lt;br /&gt;
&lt;br /&gt;
# F, G, H and I are basic MD5 functions.&lt;br /&gt;
&lt;br /&gt;
def F(x, y, z):&lt;br /&gt;
    return (x &amp;amp; y) | ((~x) &amp;amp; z)&lt;br /&gt;
&lt;br /&gt;
def G(x, y, z):&lt;br /&gt;
    return (x &amp;amp; z) | (y &amp;amp; (~z))&lt;br /&gt;
&lt;br /&gt;
def H(x, y, z):&lt;br /&gt;
    return x ^ y ^ z&lt;br /&gt;
&lt;br /&gt;
def I(x, y, z):&lt;br /&gt;
    return y ^ (x | (~z))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def XX(func, a, b, c, d, x, s, ac):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Wrapper for call distribution to functions F, G, H and I.&lt;br /&gt;
&lt;br /&gt;
    This replaces functions FF, GG, HH and II from &amp;quot;Appl. Crypto.&lt;br /&gt;
    Rotation is separate from addition to prevent recomputation&lt;br /&gt;
    (now summed-up in one function).&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    res = 0L&lt;br /&gt;
    res = res + a + func(b, c, d)&lt;br /&gt;
    res = res + x &lt;br /&gt;
    res = res + ac&lt;br /&gt;
    res = res &amp;amp; 0xffffffffL&lt;br /&gt;
    res = _rotateLeft(res, s)&lt;br /&gt;
    res = res &amp;amp; 0xffffffffL&lt;br /&gt;
    res = res + b&lt;br /&gt;
&lt;br /&gt;
    return res &amp;amp; 0xffffffffL&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MD5:&lt;br /&gt;
    &amp;quot;An implementation of the MD5 hash function in pure Python.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        &amp;quot;Initialisation.&amp;quot;&lt;br /&gt;
        &lt;br /&gt;
        # Initial 128 bit message digest (4 times 32 bit).&lt;br /&gt;
        self.A = 0L&lt;br /&gt;
        self.B = 0L&lt;br /&gt;
        self.C = 0L&lt;br /&gt;
        self.D = 0L&lt;br /&gt;
        &lt;br /&gt;
        # Initial message length in bits(!).&lt;br /&gt;
        self.length = 0L&lt;br /&gt;
        self.count = [0, 0]&lt;br /&gt;
&lt;br /&gt;
        # Initial empty message as a sequence of bytes (8 bit characters).&lt;br /&gt;
        self.input = []&lt;br /&gt;
&lt;br /&gt;
        # Length of the final hash (in bytes).&lt;br /&gt;
        self.HASH_LENGTH = 16&lt;br /&gt;
         &lt;br /&gt;
        # Length of a block (the number of bytes hashed in every transform).&lt;br /&gt;
        self.DATA_LENGTH = 64&lt;br /&gt;
&lt;br /&gt;
        # Call a separate init function, that can be used repeatedly&lt;br /&gt;
        # to start from scratch on the same object.&lt;br /&gt;
        self.init()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def init(self):&lt;br /&gt;
        &amp;quot;Initialize the message-digest and set all fields to zero.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        self.length = 0L&lt;br /&gt;
        self.input = []&lt;br /&gt;
&lt;br /&gt;
        # Load magic initialization constants.&lt;br /&gt;
        self.A = 0x67452301L&lt;br /&gt;
        self.B = 0xefcdab89L&lt;br /&gt;
        self.C = 0x98badcfeL&lt;br /&gt;
        self.D = 0x10325476L&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def _transform(self, inp):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Basic MD5 step transforming the digest based on the input.&lt;br /&gt;
&lt;br /&gt;
        Note that if the Mysterious Constants are arranged backwards&lt;br /&gt;
        in little-endian order and decrypted with the DES they produce&lt;br /&gt;
        OCCULT MESSAGES!&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        a, b, c, d = A, B, C, D = self.A, self.B, self.C, self.D&lt;br /&gt;
&lt;br /&gt;
        # Round 1.&lt;br /&gt;
&lt;br /&gt;
        S11, S12, S13, S14 = 7, 12, 17, 22&lt;br /&gt;
&lt;br /&gt;
        a = XX(F, a, b, c, d, inp[ 0], S11, 0xD76AA478L) # 1 &lt;br /&gt;
        d = XX(F, d, a, b, c, inp[ 1], S12, 0xE8C7B756L) # 2 &lt;br /&gt;
        c = XX(F, c, d, a, b, inp[ 2], S13, 0x242070DBL) # 3 &lt;br /&gt;
        b = XX(F, b, c, d, a, inp[ 3], S14, 0xC1BDCEEEL) # 4 &lt;br /&gt;
        a = XX(F, a, b, c, d, inp[ 4], S11, 0xF57C0FAFL) # 5 &lt;br /&gt;
        d = XX(F, d, a, b, c, inp[ 5], S12, 0x4787C62AL) # 6 &lt;br /&gt;
        c = XX(F, c, d, a, b, inp[ 6], S13, 0xA8304613L) # 7 &lt;br /&gt;
        b = XX(F, b, c, d, a, inp[ 7], S14, 0xFD469501L) # 8 &lt;br /&gt;
        a = XX(F, a, b, c, d, inp[ 8], S11, 0x698098D8L) # 9 &lt;br /&gt;
        d = XX(F, d, a, b, c, inp[ 9], S12, 0x8B44F7AFL) # 10 &lt;br /&gt;
        c = XX(F, c, d, a, b, inp[10], S13, 0xFFFF5BB1L) # 11 &lt;br /&gt;
        b = XX(F, b, c, d, a, inp[11], S14, 0x895CD7BEL) # 12 &lt;br /&gt;
        a = XX(F, a, b, c, d, inp[12], S11, 0x6B901122L) # 13 &lt;br /&gt;
        d = XX(F, d, a, b, c, inp[13], S12, 0xFD987193L) # 14 &lt;br /&gt;
        c = XX(F, c, d, a, b, inp[14], S13, 0xA679438EL) # 15 &lt;br /&gt;
        b = XX(F, b, c, d, a, inp[15], S14, 0x49B40821L) # 16 &lt;br /&gt;
&lt;br /&gt;
        # Round 2.&lt;br /&gt;
&lt;br /&gt;
        S21, S22, S23, S24 = 5, 9, 14, 20&lt;br /&gt;
&lt;br /&gt;
        a = XX(G, a, b, c, d, inp[ 1], S21, 0xF61E2562L) # 17 &lt;br /&gt;
        d = XX(G, d, a, b, c, inp[ 6], S22, 0xC040B340L) # 18 &lt;br /&gt;
        c = XX(G, c, d, a, b, inp[11], S23, 0x265E5A51L) # 19 &lt;br /&gt;
        b = XX(G, b, c, d, a, inp[ 0], S24, 0xE9B6C7AAL) # 20 &lt;br /&gt;
        a = XX(G, a, b, c, d, inp[ 5], S21, 0xD62F105DL) # 21 &lt;br /&gt;
        d = XX(G, d, a, b, c, inp[10], S22, 0x02441453L) # 22 &lt;br /&gt;
        c = XX(G, c, d, a, b, inp[15], S23, 0xD8A1E681L) # 23 &lt;br /&gt;
        b = XX(G, b, c, d, a, inp[ 4], S24, 0xE7D3FBC8L) # 24 &lt;br /&gt;
        a = XX(G, a, b, c, d, inp[ 9], S21, 0x21E1CDE6L) # 25 &lt;br /&gt;
        d = XX(G, d, a, b, c, inp[14], S22, 0xC33707D6L) # 26 &lt;br /&gt;
        c = XX(G, c, d, a, b, inp[ 3], S23, 0xF4D50D87L) # 27 &lt;br /&gt;
        b = XX(G, b, c, d, a, inp[ 8], S24, 0x455A14EDL) # 28 &lt;br /&gt;
        a = XX(G, a, b, c, d, inp[13], S21, 0xA9E3E905L) # 29 &lt;br /&gt;
        d = XX(G, d, a, b, c, inp[ 2], S22, 0xFCEFA3F8L) # 30 &lt;br /&gt;
        c = XX(G, c, d, a, b, inp[ 7], S23, 0x676F02D9L) # 31 &lt;br /&gt;
        b = XX(G, b, c, d, a, inp[12], S24, 0x8D2A4C8AL) # 32 &lt;br /&gt;
&lt;br /&gt;
        # Round 3.&lt;br /&gt;
&lt;br /&gt;
        S31, S32, S33, S34 = 4, 11, 16, 23&lt;br /&gt;
&lt;br /&gt;
        a = XX(H, a, b, c, d, inp[ 5], S31, 0xFFFA3942L) # 33 &lt;br /&gt;
        d = XX(H, d, a, b, c, inp[ 8], S32, 0x8771F681L) # 34 &lt;br /&gt;
        c = XX(H, c, d, a, b, inp[11], S33, 0x6D9D6122L) # 35 &lt;br /&gt;
        b = XX(H, b, c, d, a, inp[14], S34, 0xFDE5380CL) # 36 &lt;br /&gt;
        a = XX(H, a, b, c, d, inp[ 1], S31, 0xA4BEEA44L) # 37 &lt;br /&gt;
        d = XX(H, d, a, b, c, inp[ 4], S32, 0x4BDECFA9L) # 38 &lt;br /&gt;
        c = XX(H, c, d, a, b, inp[ 7], S33, 0xF6BB4B60L) # 39 &lt;br /&gt;
        b = XX(H, b, c, d, a, inp[10], S34, 0xBEBFBC70L) # 40 &lt;br /&gt;
        a = XX(H, a, b, c, d, inp[13], S31, 0x289B7EC6L) # 41 &lt;br /&gt;
        d = XX(H, d, a, b, c, inp[ 0], S32, 0xEAA127FAL) # 42 &lt;br /&gt;
        c = XX(H, c, d, a, b, inp[ 3], S33, 0xD4EF3085L) # 43 &lt;br /&gt;
        b = XX(H, b, c, d, a, inp[ 6], S34, 0x04881D05L) # 44 &lt;br /&gt;
        a = XX(H, a, b, c, d, inp[ 9], S31, 0xD9D4D039L) # 45 &lt;br /&gt;
        d = XX(H, d, a, b, c, inp[12], S32, 0xE6DB99E5L) # 46 &lt;br /&gt;
        c = XX(H, c, d, a, b, inp[15], S33, 0x1FA27CF8L) # 47 &lt;br /&gt;
        b = XX(H, b, c, d, a, inp[ 2], S34, 0xC4AC5665L) # 48 &lt;br /&gt;
&lt;br /&gt;
        # Round 4.&lt;br /&gt;
&lt;br /&gt;
        S41, S42, S43, S44 = 6, 10, 15, 21&lt;br /&gt;
&lt;br /&gt;
        a = XX(I, a, b, c, d, inp[ 0], S41, 0xF4292244L) # 49 &lt;br /&gt;
        d = XX(I, d, a, b, c, inp[ 7], S42, 0x432AFF97L) # 50 &lt;br /&gt;
        c = XX(I, c, d, a, b, inp[14], S43, 0xAB9423A7L) # 51 &lt;br /&gt;
        b = XX(I, b, c, d, a, inp[ 5], S44, 0xFC93A039L) # 52 &lt;br /&gt;
        a = XX(I, a, b, c, d, inp[12], S41, 0x655B59C3L) # 53 &lt;br /&gt;
        d = XX(I, d, a, b, c, inp[ 3], S42, 0x8F0CCC92L) # 54 &lt;br /&gt;
        c = XX(I, c, d, a, b, inp[10], S43, 0xFFEFF47DL) # 55 &lt;br /&gt;
        b = XX(I, b, c, d, a, inp[ 1], S44, 0x85845DD1L) # 56 &lt;br /&gt;
        a = XX(I, a, b, c, d, inp[ 8], S41, 0x6FA87E4FL) # 57 &lt;br /&gt;
        d = XX(I, d, a, b, c, inp[15], S42, 0xFE2CE6E0L) # 58 &lt;br /&gt;
        c = XX(I, c, d, a, b, inp[ 6], S43, 0xA3014314L) # 59 &lt;br /&gt;
        b = XX(I, b, c, d, a, inp[13], S44, 0x4E0811A1L) # 60 &lt;br /&gt;
        a = XX(I, a, b, c, d, inp[ 4], S41, 0xF7537E82L) # 61 &lt;br /&gt;
        d = XX(I, d, a, b, c, inp[11], S42, 0xBD3AF235L) # 62 &lt;br /&gt;
        c = XX(I, c, d, a, b, inp[ 2], S43, 0x2AD7D2BBL) # 63 &lt;br /&gt;
        b = XX(I, b, c, d, a, inp[ 9], S44, 0xEB86D391L) # 64 &lt;br /&gt;
&lt;br /&gt;
        A = (A + a) &amp;amp; 0xffffffffL&lt;br /&gt;
        B = (B + b) &amp;amp; 0xffffffffL&lt;br /&gt;
        C = (C + c) &amp;amp; 0xffffffffL&lt;br /&gt;
        D = (D + d) &amp;amp; 0xffffffffL&lt;br /&gt;
&lt;br /&gt;
        self.A, self.B, self.C, self.D = A, B, C, D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    # Down from here all methods follow the Python Standard Library&lt;br /&gt;
    # API of the md5 module.&lt;br /&gt;
&lt;br /&gt;
    def update(self, inBuf):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Add to the current message.&lt;br /&gt;
&lt;br /&gt;
        Update the md5 object with the string arg. Repeated calls&lt;br /&gt;
        are equivalent to a single call with the concatenation of all&lt;br /&gt;
        the arguments, i.e. m.update(a); m.update(b) is equivalent&lt;br /&gt;
        to m.update(a+b).&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        leninBuf = long(len(inBuf))&lt;br /&gt;
&lt;br /&gt;
        # Compute number of bytes mod 64.&lt;br /&gt;
        index = (self.count[0] &amp;gt;&amp;gt; 3) &amp;amp; 0x3FL&lt;br /&gt;
&lt;br /&gt;
        # Update number of bits.&lt;br /&gt;
        self.count[0] = self.count[0] + (leninBuf &amp;lt;&amp;lt; 3)&lt;br /&gt;
        if self.count[0] &amp;lt; (leninBuf &amp;lt;&amp;lt; 3):&lt;br /&gt;
            self.count[1] = self.count[1] + 1&lt;br /&gt;
        self.count[1] = self.count[1] + (leninBuf &amp;gt;&amp;gt; 29)&lt;br /&gt;
&lt;br /&gt;
        partLen = 64 - index&lt;br /&gt;
&lt;br /&gt;
        if leninBuf &amp;gt;= partLen:&lt;br /&gt;
            self.input[index:] = map(None, inBuf[:partLen])&lt;br /&gt;
            self._transform(_bytelist2long(self.input))&lt;br /&gt;
            i = partLen&lt;br /&gt;
            while i + 63 &amp;lt; leninBuf:&lt;br /&gt;
                self._transform(_bytelist2long(map(None, inBuf[i:i+64])))&lt;br /&gt;
                i = i + 64&lt;br /&gt;
            else:&lt;br /&gt;
                self.input = map(None, inBuf[i:leninBuf])&lt;br /&gt;
        else:&lt;br /&gt;
            i = 0&lt;br /&gt;
            self.input = self.input + map(None, inBuf)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def digest(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Terminate the message-digest computation and return digest.&lt;br /&gt;
&lt;br /&gt;
        Return the digest of the strings passed to the update()&lt;br /&gt;
        method so far. This is a 16-byte string which may contain&lt;br /&gt;
        non-ASCII characters, including null bytes.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        A = self.A&lt;br /&gt;
        B = self.B&lt;br /&gt;
        C = self.C&lt;br /&gt;
        D = self.D&lt;br /&gt;
        input = [] + self.input&lt;br /&gt;
        count = [] + self.count&lt;br /&gt;
&lt;br /&gt;
        index = (self.count[0] &amp;gt;&amp;gt; 3) &amp;amp; 0x3fL&lt;br /&gt;
&lt;br /&gt;
        if index &amp;lt; 56:&lt;br /&gt;
            padLen = 56 - index&lt;br /&gt;
        else:&lt;br /&gt;
            padLen = 120 - index&lt;br /&gt;
&lt;br /&gt;
        padding = [&amp;#039;\200&amp;#039;] + [&amp;#039;\000&amp;#039;] * 63&lt;br /&gt;
        self.update(padding[:padLen])&lt;br /&gt;
&lt;br /&gt;
        # Append length (before padding).&lt;br /&gt;
        bits = _bytelist2long(self.input[:56]) + count&lt;br /&gt;
&lt;br /&gt;
        self._transform(bits)&lt;br /&gt;
&lt;br /&gt;
        # Store state in digest.&lt;br /&gt;
        digest = _long2bytes(self.A &amp;lt;&amp;lt; 96, 16)[:4] + \&lt;br /&gt;
                 _long2bytes(self.B &amp;lt;&amp;lt; 64, 16)[4:8] + \&lt;br /&gt;
                 _long2bytes(self.C &amp;lt;&amp;lt; 32, 16)[8:12] + \&lt;br /&gt;
                 _long2bytes(self.D, 16)[12:]&lt;br /&gt;
&lt;br /&gt;
        self.A = A &lt;br /&gt;
        self.B = B&lt;br /&gt;
        self.C = C&lt;br /&gt;
        self.D = D&lt;br /&gt;
        self.input = input &lt;br /&gt;
        self.count = count &lt;br /&gt;
&lt;br /&gt;
        return digest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def hexdigest(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Terminate and return digest in HEX form.&lt;br /&gt;
&lt;br /&gt;
        Like digest() except the digest is returned as a string of&lt;br /&gt;
        length 32, containing only hexadecimal digits. This may be&lt;br /&gt;
        used to exchange the value safely in email or other non-&lt;br /&gt;
        binary environments.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        d = map(None, self.digest())&lt;br /&gt;
        d = map(ord, d)&lt;br /&gt;
        d = map(lambda x:&amp;quot;%02x&amp;quot; % x, d)&lt;br /&gt;
        d = string.join(d, &amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
        return d&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def copy(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Return a clone object.&lt;br /&gt;
&lt;br /&gt;
        Return a copy (&amp;#039;clone&amp;#039;) of the md5 object. This can be used&lt;br /&gt;
        to efficiently compute the digests of strings that share&lt;br /&gt;
        a common initial substring.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return copy.deepcopy(self)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ======================================================================&lt;br /&gt;
# Mimick Python top-level functions from standard library API&lt;br /&gt;
# for consistency with the md5 module of the standard library.&lt;br /&gt;
# ======================================================================&lt;br /&gt;
&lt;br /&gt;
def new(arg=None):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Return a new md5 object.&lt;br /&gt;
&lt;br /&gt;
    If arg is present, the method call update(arg) is made.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    md5 = MD5()&lt;br /&gt;
    if arg:&lt;br /&gt;
        md5.update(arg)&lt;br /&gt;
&lt;br /&gt;
    return md5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def md5(arg=None):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Same as new().&lt;br /&gt;
&lt;br /&gt;
    For backward compatibility reasons, this is an alternative&lt;br /&gt;
    name for the new() function.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    return new(arg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
</feed>