Other articles


  1. Simple XOR Hash

    NOTE: I originally posted this on Snipplr.

    This is a simple hash that pads its input to the block size and XORs every block together. Output is in hexadecimal octets. Probability of collisions is extremely high and they are easy to calculate, although the function is one-way, so this is …

    read more
  2. ARC4

    NOTE: I originally posted this on Snipplr.

    This is a pure Python implementation of ARC4 as a generator to highlight its nature as a stream cipher. Several improvements can be made, for instance, it could take a nonce, use multiple state spaces (parallelizable), automatically discard the first 4K of the …

    read more
  3. HMAC

    NOTE: I originally posted this on Snipplr.

    To HMAC, pass a hash from Crypto.Hash in PyCrypto. Key should be a bytes object. Returns a bytearray.

    def pad_key(a_hash, a_key):
        block_size = a_hash.digest_size
    
        if (len(a_key) > block_size):
            a_hasher = a_hash.new()
            a_hash.update(a_key)
            return a_hasher.digest()
        elif (len(a_key) < block_size …
    read more

Sections