A simple hash function
phanerography·@johan-nygren·
0.000 HBDA simple hash function
The message M is input into a hash function, as Mn where n is the iteration of the function (M0, M1...Mn), also used as a nonce that is incremented every iteration of the function. Mn will here be referred to as just M. M maps to bit x = M%(bits(M)-n) in M. This bit is sliced from M. The value for M with the bit sliced, Mi (intermediary state), maps to a bit y in the original message M, y = Mi%(bits(M)-n), and the bit x is transformed with a XOR operation, x⊕y, and moved to the leftmost bit in M. The nonce n is incremented by 1, n += 1 (the loop iterates), and the process is repeated for every bit in M. ``` import random def iterator(mutator, n): x = 1 + int(mutator, 2)%(len(mutator)-n) bitX = mutator[len(mutator)-x] firstHalf = mutator[len(mutator)-x+1 : len(mutator)] secondHalf = mutator[0 : len(mutator)-x] intermediary = secondHalf + firstHalf y = 1 + int(intermediary, 2)%len(mutator) bitY = mutator[len(mutator)-y] newBit = int(bitX, 2)^int(bitY, 2) newMessage = bin(newBit)[2:] + intermediary return newMessage def hashFunction(number): print(number) mutator = bin(number)[2:] for x in range(len(mutator)): mutator = iterator(mutator, x) return mutator print(int(hashFunction(random.getrandbits(256)),2)) ```