示例#1
0
    def finalstep(input, magic_key_char, table):
        def finalxor(hash, mask):
            result = array('B')
            for c in hash:
                result.append(ord(c) ^ mask)
            for c in range(64 - len(hash)):
                result.append(mask)
            return result.tostring()

        hash = md5.new(input).digest().encode('base64').translate(
            base64translate, '\r\n')

        if (
                table >= 3
        ):  # We have to use the slow sha1 implementation to get to it's internals
            sha1 = pysha.new(finalxor(hash, 0x36) + magic_key_char)
            sha1.count[1] = sha1.count[1] - 1
        else:
            sha1 = sha.new(finalxor(hash, 0x36) + magic_key_char)
        digest1 = sha1.digest()
        digest2 = sha.new(finalxor(hash, 0x5c) + digest1).digest()

        result = ''
        for i in range(10):
            # First two bytes of digest stuffed together.
            val = (ord(digest2[i * 2]) << 8) + ord(digest2[i * 2 + 1])

            result += alphabet1[(val >> 0x0b) & 0x1f] + '='
            result += alphabet2[(val >> 0x06) & 0x1f]
            result += alphabet2[(val >> 0x01) & 0x1f]
            result += delimit_lookup[val & 0x01]
        return result
示例#2
0
    def finalstep(input, magic_key_char, table):
        def finalxor(hash, mask):
            result = array("B")
            for c in hash:
                result.append(ord(c) ^ mask)
            for c in range(64 - len(hash)):
                result.append(mask)
            return result.tostring()

        hash = md5.new(input).digest().encode("base64").translate(base64translate, "\r\n")

        if table >= 3:  # We have to use the slow sha1 implementation to get to it's internals
            sha1 = pysha.new(finalxor(hash, 0x36) + magic_key_char)
            sha1.count[1] = sha1.count[1] - 1
        else:
            sha1 = sha.new(finalxor(hash, 0x36) + magic_key_char)
        digest1 = sha1.digest()
        digest2 = sha.new(finalxor(hash, 0x5C) + digest1).digest()

        result = ""
        for i in range(10):
            # First two bytes of digest stuffed together.
            val = (ord(digest2[i * 2]) << 8) + ord(digest2[i * 2 + 1])

            result += alphabet1[(val >> 0x0B) & 0x1F] + "="
            result += alphabet2[(val >> 0x06) & 0x1F]
            result += alphabet2[(val >> 0x01) & 0x1F]
            result += delimit_lookup[val & 0x01]
        return result
示例#3
0
def new(data=None):
        """Create a new pure python SHA hash object
        
        data =  initial input (raw string) to the hashing object
                if present, the method call update(arg) is made
        
        EXAMPLE: FIPS 180-2
        =========
        
        >>> from CryptoPlus.Hash import python_SHA
        
        >>> message = "abc"
        >>> hasher = python_SHA.new()
        >>> hasher.update(message)
        >>> hasher.hexdigest()
        'a9993e364706816aba3e25717850c26c9cd0d89d'
        
        >>> message = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
        >>> hasher = python_SHA.new()
        >>> hasher.update(message)
        >>> hasher.hexdigest()
        '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
        """
        return pysha.new(data)
示例#4
0
def new(data=None):
    """Create a new pure python SHA hash object
        
        data =  initial input (raw string) to the hashing object
                if present, the method call update(arg) is made
        
        EXAMPLE: FIPS 180-2
        =========
        
        >>> from CryptoPlus.Hash import python_SHA
        
        >>> message = "abc"
        >>> hasher = python_SHA.new()
        >>> hasher.update(message)
        >>> hasher.hexdigest()
        'a9993e364706816aba3e25717850c26c9cd0d89d'
        
        >>> message = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
        >>> hasher = python_SHA.new()
        >>> hasher.update(message)
        >>> hasher.hexdigest()
        '84983e441c3bd26ebaae4aa1f95129e5e54670f1'
        """
    return pysha.new(data)