Popular recipes tagged "encoding"http://code.activestate.com/recipes/tags/encoding/2016-07-23T07:58:14-07:00ActiveState Code RecipesHamming Error Correction Code (Python) 2016-07-23T07:58:14-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/580691-hamming-error-correction-code/ <p style="color: grey"> Python recipe 580691 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/engineering/">engineering</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>Hamming(7,4) Error Correction Code (ECC).</p> De-chunk and decompress HTTP body (Python) 2015-06-30T03:31:31-07:00Vovanhttp://code.activestate.com/recipes/users/4192447/http://code.activestate.com/recipes/579075-de-chunk-and-decompress-http-body/ <p style="color: grey"> Python recipe 579075 by <a href="/recipes/users/4192447/">Vovan</a> (<a href="/recipes/tags/chunked/">chunked</a>, <a href="/recipes/tags/content/">content</a>, <a href="/recipes/tags/dechunking/">dechunking</a>, <a href="/recipes/tags/decompression/">decompression</a>, <a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/preprocess/">preprocess</a>, <a href="/recipes/tags/transfer/">transfer</a>). Revision 2. </p> <p>Example read_body_stream() usage:</p> <pre class="prettyprint"><code>with open(http_file_path, 'rb') as fh: print(b''.join(httputil.read_body_stream( fh, chunked=True, compression=httputil.GZIP)) </code></pre> Markov Encryption Demonstration 2 (Python) 2012-03-14T17:39:17-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578076-markov-encryption-demonstration-2/ <p style="color: grey"> Python recipe 578076 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/encode/">encode</a>, <a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/encrypt/">encrypt</a>, <a href="/recipes/tags/encryption/">encryption</a>). </p> <p>This program is meant to act as an example of how to use ME with data that needs to be obfuscated. The functionality provided via the GUI demonstrates both the ability to encrypt and decrypt all text that the UTF-8 encoding can handle. Explanations come later.</p> Markov Encryption Demonstration 1 (Python) 2012-03-16T18:59:06-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578062-markov-encryption-demonstration-1/ <p style="color: grey"> Python recipe 578062 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/encode/">encode</a>, <a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/encrypt/">encrypt</a>, <a href="/recipes/tags/encryption/">encryption</a>). </p> <p>This is a simple GUI program that shows Markov Encryption at work. It is built to be interactive and has all needed code embedded within itself. This version of ME library is not very efficient and represents an early attempt at developing and easily testing the code. Certain limits are built into the program, and the code is not meant to be robust at this stage. This program is a proof-of-concept design meant to ensure that the work being done was viable for future use and that the encryption process could be carried out both ways, both in encoding plaintext and decoding ciphertext.</p> Mazovia encoding for Polish text from MS-DOS era (Python) 2012-02-15T09:24:13-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/578040-mazovia-encoding-for-polish-text-from-ms-dos-era/ <p style="color: grey"> Python recipe 578040 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/mazovia/">mazovia</a>, <a href="/recipes/tags/polish/">polish</a>). </p> <p>Some MS-DOS era text or databases in Poland use Mazovia encoding for letters such as: ą, ę, ś, ż, ź. It is very well described on Polish wikipedia: <a href="http://pl.wikipedia.org/wiki/Mazovia_%28kod%29" rel="nofollow">http://pl.wikipedia.org/wiki/Mazovia_(kod)</a></p> <p>There is <code>mazovia.py</code> with Polish encoding. Copy it to the Python <code>Lib/encodings</code> directory. Tested with Python 2.7. For Python 3.2 I had to remove unicode string u prefix.</p> <p>Usage:</p> <pre class="prettyprint"><code>def conv_file(fname): f = codecs.open(fname, 'rb', 'mazovia') s = f.read() f.close() f = codecs.open(fname + '_utf8', 'wb', 'utf8') f.write(s) f.close() </code></pre>