User : weilawei
![]() |
Title | User | Language | Tags | Description | Date |
|---|---|---|---|---|---|---|
|
Improved ARC4 (IARC4) | weilawei | Python | Cryptography | This code is public domain. Improved ARC4 (IARC4) contains a number of improvements over naive ARC4:
It does not yet implement a more complex keystream generator or a larger state space. Additionally, this has not been cryptanalyzed and should not be considered secure or used in production. This is strictly experimental, and subject to change without notice. Tested on Python 3.2.3 with PyCrypto 2.4.1 and python-bitstring 3.0.2. |
July 20 |
|
Simple XOR Hash | weilawei | Python | hash | This is a simple hash that pads its input to the block size and XORs every block together. Output is in hexadecimal octets. |
June 2, 2012 |
|
ARC4 | weilawei | Python | stream | This is a pure Python implementation of raw ARC4, sans any improvements. For instance, it could take a nonce, use multiple state spaces (parallelizable), automatically discard the first 4K of the state space(s), use a more complex transformation than a simple swap, limit the # of bytes encrypted per nonce, etc.. The size of the state space is a parameter--the size of the key must not exceed the size of the state space. |
May 10, 2012 |
|
Chunk Data for Streaming | weilawei | Python | streaming | Chunks data into block_size blocks for streaming, adds null padding. |
May 9, 2012 |
|
All-Or-Nothing Transform | weilawei | Python | transform | Performs an all-or-nothing transform on a stream of chunks. The data can only be decrypted if every block is present to generate an HMAC for. The list of HMACs is then XOR'd against the final block from the transform, yielding the decryption key for the blocks. Currently uses the HMAC key for encryption as well (TODO: change this). Reports a hash of the encrypted chunk for storage/retrieval without needing to calculate HMAC until decryption. Needs a lot of cleanup and some fixes. Makes a lot of assumptions, for instance, that currentblock, totalblocks, and datasize only occupy 1 byte apiece. Currently doesn't strip padding after decoding, and doesn't convert original integers for currentblock, totalblocks, and datasize back from bytes. |
May 9, 2012 |
|
HMAC | weilawei | Python | hmac | HMAC, pass a hash from Crypto.Hash in PyCrypto. Key should be a bytes object. Returns a bytearray. |
May 9, 2012 |
|
A Clueless Agent Generator for Python 2.7/3.2 | weilawei | Python | key | This is an implementation of a clueless agent generator which creates self-decrypting clueless agents as described in "Environmental Key Generation towards Clueless Agents" by J. Riordan and B. Schneier. It requires Python and PyCrypto of a recent build (tested with 2.3 and higher). To use, pass a python file (or other file) to be encrypted, followed by a series of "observations" on the command line. These observations are hashed yo yield the encryption key. A signature is generated by hashing the key, and this signature will be expected to be present in the target environment. Pipe the resulting agent to a file or see the agent code directly on stdout. Additionally, there is an is_debug flag that can be specified (see the source) or tweaked in the resulting agent, to be more verbose. To attempt decryption/execution of a clueless agent, simply run the generated python script (agent) and pass a set of observations on the command line. If the hash of the hash of the observations match the signature, the hash of the observations will be used as the decryption key. If the signature does not match, the agent will exit with no output. The code previously directly exec()'d the resulting code, however, it simply outputs to stdout now. The resulting code would otherwise execute directly in-line, at that location in the program, which has many undesirable consequences. Piping it to a file and executing, piping it to a memory-backed temporary file and executing it, or placing the resulting code directly in memory afterward and then executing it, are all ways to run the code contained within. This makes it fundamentally little different from encrypting a file directly, except that the key is environmentally generated, perhaps by a daemon that feeds environmental observations on the command line to the agent. Note, that you can encrypt more than Python scripts, and agents can be made to contain themselves. $ ./agent_generator.py plaincode.py 0 > cipheragent.py $ ./agentgenerator.py cipheragent.py some more observations > doubleagent.py $ ./double_agent.py wrong observations --nothing here-- $ ./doubleagent.py some more observations > cipheragent2.py --cipheragent_2.py now holds the same content as cipheragent.py-- $ ./cipheragent.py 0 > plaincode_2.py --plaincode_2.py now holds the same content as plaincode.py-- $ ./plaincode_2.py --should yield the same as-- $ ./plaincode.py |
May 7, 2012 |
|
Axis-Aligned Bounding Box | weilawei | Clojure | box | make-aabb [a-point b-point] [a-point b-point]: Creates a 3D Axis-Aligned Bounding Box (AABB). aabb-contains? [a-box a-point]: Returns true if a 3D AABB contains a given point. |
May 7, 2012 |
|
Simple SVG Streaming Client | weilawei | HTML | ajax | This is a simple SVG streaming client, which displays the output on an HTML5 canvas element. The server can be (almost) transparently restarted (output freezes). The client allows for adjusting the FPS and changing the input stream. The server is at http://snipplr.com/view/64802/simple-svg-streaming-server/. |
May 7, 2012 |
|
Simple SVG Streaming Server | weilawei | Python | server | This is a simple SVG streaming server, running on the bottle microframework. It has 3 utility functions which are used as decorators on routes. They enable timing a route, caching a route, and creating a route which provides a Cairo context which is then converted to a Base64 encoded data URL with an SVG image. In another snippet, I give the client-side implementation using HTML, Javascript/jQuery, and Canvas. This sample can currently display a clock (clock.svg) (incorrectly rotated 90 degrees...but it wasn't enough of a priority to fix. it's just an example.), show a static line of text (window.svg), or serve static files (the necessary client-side JS and HTML). The client is at http://snipplr.com/view/64803/simple-svg-streaming-client/. |
May 7, 2012 |
|
k-d tree | weilawei | Clojure | tree | make-kd-node [median left right]: Creates a node in a kd-tree. make-kd-tree [k depth points]: Creates a kd-tree of kd-nodes. TODO: Not stack safe. Use loop/recur. kd-nearest-neighbor [a-point kd-tree]: Returns the nearest neighboring point to a given point, using a kd-tree. |
May 7, 2012 |
|
Geometrics Optics Approximation Functions | weilawei | C | geometric | Simple functions useful for the geometric optics approximation. Written to be simple and clear, not fast. |
May 7, 2012 |
|
A Symmetric Somewhat Homomorphic Encryption Implementation | weilawei | Python | Encryption | This is an implementation of a symmetric SWHE from section 3.2 of "Computing Arbitrary Functions of Encrypted Data" by Craig Gentry. It contains a small modification (namely, the addition of a modulus parameter to allow a greater-than-2-element plaintext space). Examples provided illustrate the encryption/decryption of a value, addition and multiplication, the basic AND and XOR gates, and complex gates (circuits) for NOT, OR, NAND, NOR, and IF. Note that I'm not a cryptographer, so I can't vouch for the correctness of this. If you find a bug, PLEASE let me know. Also, note that this is a toy, not production code: two functions are defined recursively, and, as Python doesn't do tail-call optimization, you can easily overflow the stack/exceed the maximum recursion depth, especially if you increase the size of the modulus further. Also, performing too many consecutive operations can easily cause values to exceed machine word size. |
March 28, 2012 |

