Popular recipes tagged "meta:requires=hashlib"http://code.activestate.com/recipes/tags/meta:requires=hashlib/2015-12-06T19:23:54-08:00ActiveState Code RecipesLibgen Epub Upload using Tor (Python) 2015-12-06T19:23:54-08:00fuji239http://code.activestate.com/recipes/users/4193238/http://code.activestate.com/recipes/579134-libgen-epub-upload-using-tor/ <p style="color: grey"> Python recipe 579134 by <a href="/recipes/users/4193238/">fuji239</a> (<a href="/recipes/tags/beautifulsoup/">beautifulsoup</a>, <a href="/recipes/tags/libgen/">libgen</a>, <a href="/recipes/tags/mechanize/">mechanize</a>, <a href="/recipes/tags/tor/">tor</a>, <a href="/recipes/tags/upload/">upload</a>). Revision 2. </p> <p>This script shows how to upload epub files in Library Genesys (libgen) automatically by using Tor. Please note that only copyright free epubs should be used (such as those present in <a href="https://www.gutenberg.org/" rel="nofollow">https://www.gutenberg.org/</a>). It will also check if MD5 hash is present before uploading. This is provided for python educative purposes only : it shows how to use a Tor proxy, Mechanize (for uploading and form processing), Hashlib for MD5 calculation, Filemagic for mimetype detecting and BeautifulSoup for response analyzing, all together.</p> Save and restore SHA-512 internal state (Python) 2013-03-03T18:05:42-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/578479-save-and-restore-sha-512-internal-state/ <p style="color: grey"> Python recipe 578479 by <a href="/recipes/users/4068698/">Dima Tisnek</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/inner/">inner</a>, <a href="/recipes/tags/pickle/">pickle</a>, <a href="/recipes/tags/restore/">restore</a>, <a href="/recipes/tags/sha512/">sha512</a>, <a href="/recipes/tags/state/">state</a>). </p> <p>If you have a very long input to hash, you may want to save your progress.</p> <p>CPython doesn't normally let you, but it's easy to hack around via ctypes</p> Storing a Single Username and Encrypted Password to a File (Python) 2013-01-31T02:07:25-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578443-storing-a-single-username-and-encrypted-password-t/ <p style="color: grey"> Python recipe 578443 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This script was written for an article I wrote to check user passwords. It stores data using SHA one-way function. For more information <a href="http://thelivingpearl.com/2013/01/29/authentication-of-users-and-passwords-in-python/">Authentication Of Users And Passwords In Python</a></p> Code To Store Encrypted Password in a File (Python) 2013-01-19T04:07:50-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578430-code-to-store-encrypted-password-in-a-file/ <p style="color: grey"> Python recipe 578430 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This snippet of code was written as part of an article - <a href="http://thelivingpearl.com/2013/01/18/password-protecting-your-python-application/">Password Protecting You Python Application</a></p> Verify Username and Password Using a File for Storage (Python) 2013-01-31T02:11:24-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578446-verify-username-and-password-using-a-file-for-stor/ <p style="color: grey"> Python recipe 578446 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/usernames/">usernames</a>). </p> <p>This script was written for an article I wrote to check user passwords. It stores data using SHA one-way function. For more information <a href="http://thelivingpearl.com/2013/01/29/authentication-of-users-and-passwords-in-python/">Authentication Of Users And Passwords In Python</a></p> Verify a Single User Name and Password in Python (Python) 2013-01-31T02:09:58-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578445-verify-a-single-user-name-and-password-in-python/ <p style="color: grey"> Python recipe 578445 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/usernames/">usernames</a>). </p> <p>This script was written for an article I wrote to check user passwords. It stores data using SHA one-way function. For more information <a href="http://thelivingpearl.com/2013/01/29/authentication-of-users-and-passwords-in-python/">Authentication Of Users And Passwords In Python</a></p> Appending Encrypted Username and Passwords to a File (Python) 2013-01-31T02:08:20-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578444-appending-encrypted-username-and-passwords-to-a-fi/ <p style="color: grey"> Python recipe 578444 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This script was written for an article I wrote to check user passwords. It stores data using SHA one-way function. For more information <a href="http://thelivingpearl.com/2013/01/29/authentication-of-users-and-passwords-in-python/">Authentication Of Users And Passwords In Python</a></p> Promot & Verify Encrypted User Password (Python) 2013-01-19T04:10:13-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578431-promot-verify-encrypted-user-password/ <p style="color: grey"> Python recipe 578431 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This snippet of code was written as part of an article - <a href="http://thelivingpearl.com/2013/01/18/password-protecting-your-python-application/">Password Protecting You Python Application</a>. The code requires a file with an encrypted password. The script to generate an encrypted file is <a href="http://code.activestate.com/recipes/578430-code-to-store-encrypted-password-in-a-file/">Code To Store Encrypted Password in a File</a>.</p> WebSocket interface (Python) 2012-11-25T16:52:21-08:00Nick Farohttp://code.activestate.com/recipes/users/4184363/http://code.activestate.com/recipes/578348-websocket-interface/ <p style="color: grey"> Python recipe 578348 by <a href="/recipes/users/4184363/">Nick Faro</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/socket/">socket</a>, <a href="/recipes/tags/websocket/">websocket</a>). Revision 2. </p> <p>This tries its best to be a replacement for the regular <code>socket</code> module.</p> <p>It supports only sending and receiving but should be useful enough.</p> <p>The only real difference should be that you can't specify the number of bytes is received, instead do</p> <pre class="prettyprint"><code>for message in socket.recv(): print(message) </code></pre> <p>Revision 2: Added proper message receiving. Previously it just requested a ton of data. Now it reads 2 bytes, determines the length, then requests that much.</p> Manage hashes in database files. (Python) 2012-03-24T14:40:24-07:00eysihttp://code.activestate.com/recipes/users/4177096/http://code.activestate.com/recipes/578081-manage-hashes-in-database-files/ <p style="color: grey"> Python recipe 578081 by <a href="/recipes/users/4177096/">eysi</a> (<a href="/recipes/tags/caching/">caching</a>, <a href="/recipes/tags/hashes/">hashes</a>). Revision 4. </p> <p>This module can be used to calculate file hashes, store them in a database file and retrieve them at a later date.</p> <p>It uses the files modify time stamp to know if it can use the hash stored in the db or if it has to re-calculate it. So the user will not have to worry about the hash being incorrect if the file changes in between runs.</p> Manage hashes in database files. (Python) 2012-03-20T01:08:15-07:00cathy parkhttp://code.activestate.com/recipes/users/4181365/http://code.activestate.com/recipes/578083-manage-hashes-in-database-files/ <p style="color: grey"> Python recipe 578083 by <a href="/recipes/users/4181365/">cathy park</a> (<a href="/recipes/tags/caching/">caching</a>, <a href="/recipes/tags/hashes/">hashes</a>). </p> <p>This module can be used to calculate file hashes, store them in a database file and retrieve them at a later date.</p> <p>It uses the files modify time stamp to know if it can use the hash stored in the db or if it has to re-calculate it. So the user will not have to worry about the hash being incorrect if the file changes in between runs.</p> Rsync Algorithm (Python) 2011-01-09T16:32:22-08:00Eric Pruitthttp://code.activestate.com/recipes/users/4170757/http://code.activestate.com/recipes/577518-rsync-algorithm/ <p style="color: grey"> Python recipe 577518 by <a href="/recipes/users/4170757/">Eric Pruitt</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/delta/">delta</a>, <a href="/recipes/tags/diff/">diff</a>, <a href="/recipes/tags/patch/">patch</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/rsync/">rsync</a>). Revision 4. </p> <p>This is a pure Python implementation of the <a href="http://samba.anu.edu.au/rsync/">rsync algorithm</a>. On my desktop (3.0GHz dual core, 7200RPM), best case throughput for target file hash generation and delta generation is around 2.9MB/s. Absolute worst case scenario (no blocks in common) throughput for delta generation is 200KB/s to 300KB/s on the same system.</p> <p>Tested in Python 2.5, 2.6, and 3.1. In 2.7, io.BufferedReader should yield the best throughput. On all other versions use __builtin__.open.</p> Bloom Filter (Python) 2011-05-05T07:25:01-07:00Sundar Srinivasanhttp://code.activestate.com/recipes/users/4177884/http://code.activestate.com/recipes/577686-bloom-filter/ <p style="color: grey"> Python recipe 577686 by <a href="/recipes/users/4177884/">Sundar Srinivasan</a> (<a href="/recipes/tags/big_table/">big_table</a>, <a href="/recipes/tags/bloom_filter/">bloom_filter</a>, <a href="/recipes/tags/sets/">sets</a>, <a href="/recipes/tags/spelling_checker/">spelling_checker</a>). Revision 2. </p> <p>Space efficient, probabilistic set membership tester. Has no False Negatives but allows a rare False Positive.</p> Python Sessions (Python) 2011-01-08T03:23:05-08:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577524-python-sessions/ <p style="color: grey"> Python recipe 577524 by <a href="/recipes/users/4174115/">Sunjay Varma</a> (<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/cookie/">cookie</a>, <a href="/recipes/tags/management/">management</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/sessions/">sessions</a>). Revision 2. </p> <p>I think this script should now be functional enough to post here at ActiveState. When you reply or vote down, please post some information on your problem with the code, and if you can, maybe something about the solution. This interface works, and is designed especially for Python. If you like it, don't be afraid to post that either, constructive criticism is all good, but compliments are even better! ;)</p> <p>Get the latest version of this code here: <a href="http://wiki.sunjay.ca/Python:Contents/Python_Session" rel="nofollow">http://wiki.sunjay.ca/Python:Contents/Python_Session</a></p> <p><strong>Latest Changes:</strong></p> <ul> <li>Added a new function for making the session cookie last longer. See code for <code>set_expires</code>. Note: This new function is just in case you need to include a session for longer than one brower session (for example, one day instead). </li> </ul> Getting the SHA-1 (or MD5) hash of a directory (Python) 2009-12-06T19:02:40-08:00Stephen Akikihttp://code.activestate.com/recipes/users/4172143/http://code.activestate.com/recipes/576973-getting-the-sha-1-or-md5-hash-of-a-directory/ <p style="color: grey"> Python recipe 576973 by <a href="/recipes/users/4172143/">Stephen Akiki</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/getting/">getting</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/md5/">md5</a>, <a href="/recipes/tags/sha_1/">sha_1</a>, <a href="/recipes/tags/the/">the</a>). Revision 4. </p> <h5><a href="http://akiscode.com/articles/sha-1directoryhash.shtml" rel="nofollow">http://akiscode.com/articles/sha-1directoryhash.shtml</a></h5> <p>By definition a cryptographic hash is, "a deterministic procedure that takes an arbitrary block of data and returns a fixed-size bit string, the (cryptographic) hash value, such that an accidental or intentional change to the data will change the hash value". </p> <p>Usually these hashes are used on files to "fingerprint" them, but in order to do the same to a directory you have to do something like this: </p> SimpleCryptSocketExt - SimpleCrypt Wrapper for Easy Socket, Client / Server Encryption (Python) 2010-05-07T15:33:06-07:00AJ. Mayorgahttp://code.activestate.com/recipes/users/4173476/http://code.activestate.com/recipes/577212-simplecryptsocketext-simplecrypt-wrapper-for-easy-/ <p style="color: grey"> Python recipe 577212 by <a href="/recipes/users/4173476/">AJ. Mayorga</a> (<a href="/recipes/tags/client_server/">client_server</a>, <a href="/recipes/tags/cryptography/">cryptography</a>, <a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/server/">server</a>, <a href="/recipes/tags/socket/">socket</a>). Revision 5. </p> <p>Lightweight drop-in encryption wrapper for various Client/Server solutions supporting protocols such as UDP, TCP, HTTP, HTTPS, FTP, RAW Sockets etc.</p> Authenticated encryption with PyCrypto (Python) 2010-01-26T16:05:50-08:00Daniel Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/576980-authenticated-encryption-with-pycrypto/ <p style="color: grey"> Python recipe 576980 by <a href="/recipes/users/4016391/">Daniel Miller</a> (<a href="/recipes/tags/aes/">aes</a>, <a href="/recipes/tags/encrypt/">encrypt</a>, <a href="/recipes/tags/hmac/">hmac</a>, <a href="/recipes/tags/pycrypto/">pycrypto</a>). Revision 3. </p> <p>PyCrypto-based authenticated encryption using AES-CBC and HMAC-SHA256. This class only supports shared secret encryption. Look elsewhere for public key encryption.</p> Simple Small Tweakable Encryption Solution -- SimpleCrypt (Python) 2010-04-30T21:00:26-07:00AJ. Mayorgahttp://code.activestate.com/recipes/users/4173476/http://code.activestate.com/recipes/577174-simple-small-tweakable-encryption-solution-simplec/ <p style="color: grey"> Python recipe 577174 by <a href="/recipes/users/4173476/">AJ. Mayorga</a> (<a href="/recipes/tags/crypt/">crypt</a>, <a href="/recipes/tags/cryptography/">cryptography</a>, <a href="/recipes/tags/encryption/">encryption</a>). Revision 6. </p> <p>Encryption can sometimes be a nightmare, at least is my experience while Python has some excellent resources for encryption I found myself a lot of times needing an encryption solution that could port easily between VS C++, .NET, PHP, and Python projects that would be simple to implement and not rely on large bloated crypto libs.</p> Python 3 WSGI Server (Python) 2009-09-22T11:36:30-07:00poops mcgeehttp://code.activestate.com/recipes/users/4171745/http://code.activestate.com/recipes/576906-python-3-wsgi-server/ <p style="color: grey"> Python recipe 576906 by <a href="/recipes/users/4171745/">poops mcgee</a> . Revision 2. </p> <p>This is a simplified version of tornado's WSGI server implemented in python 3.</p> <p>Example usage:</p> <pre class="prettyprint"><code>import web import wsgiref.simple_server class MainHandler(web.RequestHandler): def get(self): self.write("Hello, world") if __name__ == "__main__": application = web.WSGIApplication([ (r"/", MainHandler), ]) server = wsgiref.simple_server.make_server('', 8888, application) server.serve_forever() </code></pre> Locate thumbnail file (Python) 2009-11-02T06:22:33-08:00Rajahttp://code.activestate.com/recipes/users/4172172/http://code.activestate.com/recipes/576942-locate-thumbnail-file/ <p style="color: grey"> Python recipe 576942 by <a href="/recipes/users/4172172/">Raja</a> (<a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/thumbnail/">thumbnail</a>). Revision 2. </p> <p>On unix systems following the free desktop standards, locate the thumbnail image for any file, if present. Needs Python 2.5.</p>