I’ve recently developed a Python script for encoding messages or data using a rather intricate algorithm, I must say. To be transparent, I drew inspiration from certain elements I came across in the Cloudflare Turnstile Captcha files, which are commonly associated with website security measures. My endeavor primarily involved meticulously recreating and adapting these elements into a Python script.
Code:
class HashGenerator:
@staticmethod
def _hash_function(data):
def b(f, g):
i = (65535 & f) + (65535 & g)
return ((f >> 16) + (g >> 16) + (i >> 16)) << 16 | (i & 65535)
def c(d, f):
return (d << (32 - f)) | (d >> f)
padding = b'\x80' + b'\x00' * (55 - (len(data) + 8) % 64)
data += padding + (len(data) * 8).to_bytes(8, byteorder='big')
w = [0] * 64
for i in range(0, len(data), 64):
for j in range(16):
w[j] = int.from_bytes(data[i + j * 4:i + j * 4 + 4], byteorder='big')
for j in range(16, 64):
s0 = (c(w[j - 15], 7) ^ c(w[j - 15], 18) ^ (w[j - 15] >> 3))
s1 = (c(w[j - 2], 17) ^ c(w[j - 2], 19) ^ (w[j - 2] >> 10))
w[j] = (w[j - 16] + s0 + w[j - 7] + s1) & 0xFFFFFFFF
o = [
1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221,
3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580,
3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,
2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895,
666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037,
2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344,
430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779,
1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298
]
s = [
1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225
]
A, B, C, D, E, F, G, H = s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7]
for i in range(64):
S1 = (c(E, 6) ^ c(E, 11) ^ c(E, 25))
ch = ((E & F) ^ ((~E) & G))
temp1 = (H + S1 + ch + o[i] + w[i]) & 0xFFFFFFFF
S0 = (c(A, 2) ^ c(A, 13) ^ c(A, 22))
maj = ((A & B) ^ (A & C) ^ (B & C))
temp2 = (S0 + maj) & 0xFFFFFFFF
H = G
G = F
F = E
E = (D + temp1) & 0xFFFFFFFF
D = C
C = B
B = A
A = (temp1 + temp2) & 0xFFFFFFFF
s[0] = (s[0] + A) & 0xFFFFFFFF
s[1] = (s[1] + B) & 0xFFFFFFFF
s[2] = (s[2] + C) & 0xFFFFFFFF
s[3] = (s[3] + D) & 0xFFFFFFFF
s[4] = (s[4] + E) & 0xFFFFFFFF
s[5] = (s[5] + F) & 0xFFFFFFFF
s[6] = (s[6] + G) & 0xFFFFFFFF
s[7] = (s[7] + H) & 0xFFFFFFFF
result = ''
for i in s:
hex_str = hex(i)[2:]
result += '0' * (8 - len(hex_str)) + hex_str
return result
def generate_hash(self, data):
return self._hash_function(data)
if __name__ == "__main__":
hash = HashGenerator()
data = "Hello World!"
result = hash.generate_hash(data.encode())
print(result)