Cracking a hash which descends to a single value after repeated hashes Assume I have a hash function (such as the one below) and a cipher, and I know that if I repeatedly hash any string over and over again, it will eventually descend to one unique value. 

Is there any known way to crack a hash function following this pattern? Does this property lend itself to any exploitable vulnerabilities?

Hash function (in python):

def compute_hash(uinput):
    if len(uinput) &gt; 32: return
    blen = 32
    n = blen - len(uinput) % blen
    if n == 0:
        n = blen
    pad = chr(n)
    ninput = uinput + pad * n
    r = ""
    for i in range(0, blen, 4):
        s = ninput[i:i+4]
        h = 0
        for j in range(len(s)):
            h = (h &lt;&lt; 4) + ord(s[j])
            g = h &amp; 4026531840
            if not(g == 0):
                h ^= g &gt;&gt; 24
            h &amp;= ~g
        r += chr(h % 256)
    h = ""
    for c in r:
        h += c.encode("hex")
    return h
This specific hash function is weak; it appears that what this hash function does is pad out the string to be hashed into a 32 byte string, and then take the 8 4-byte substrings, and maps each substring individually into an individual byte.

This immediately makes it trivial to find a preimage; start with a random 31 byte preimage (there appears to be a bug in the code if it is presented with a 32 byte input), hash it, and for every byte of output that is wrong, modify the corresponding 4-byte substring in the preimage, and repeat until the hash is the expected value.

However, to answer the general question of whether a hash function with the specific property that is necessarily weak, well, I believe that we can produce an example of such a hash function that is not.  One such example would be:


Given the empty string, outputs the empty string
Given a string $S$ of length $L$, generates the first $L-1$ bits of $SHAKE256(S)$


This function would appear to be strong given a long input (because we believe that SHAKE256 is a strong hash function), but repeated application of this hash function eventually will cycle at the empty string.