解密函数
class Sign:
A = 1732584193
B = -271733879
C = -1732584194
D = 271733878
@staticmethod
def f(i, i2, i3):
# print(f"Sign.f is called: i={i}, i2={i2}, i3={i3}")
return ((~i) & i3) | (i2 & i)
@staticmethod
def ff(i, i2, i3, i4, i5, i6):
# print(f"Sign.ff is called: i={i}, i2={i2}, i3={i3}, i4={i4}, i5={i5}, i6={i6}")
result = Sign.rotate_left(i + Sign.f(i2, i3, i4) + i5, i6)
# print(f"Sign.ff result={result}")
return result
@staticmethod
def g(i, i2, i3):
return (i & i3) | (i & i2) | (i2 & i3)
@staticmethod
def gg(i, i2, i3, i4, i5, i6):
return Sign.rotate_left(i + Sign.g(i2, i3, i4) + i5 + 1518565785, i6)
@staticmethod
def h(i, i2, i3):
return (i ^ i2) ^ i3
@staticmethod
def hh(i, i2, i3, i4, i5, i6):
# print(f"Sign.hh is called: i={i}, i2={i2}, i3={i3}, i4={i4}, i5={i5}, i6={i6}")
result = Sign.rotate_left(i + Sign.h(i2, i3, i4) + i5 + 1859775393, i6)
# print(f"Sign.hh result={result}")
return result
def padding(self, bArr):
length = len(bArr) * 8
array_list = list(bArr)
array_list.append(128)
while ((len(array_list) * 8 + 64) % 512) != 0:
array_list.append(0)
for i in range(8):
array_list.append((length >> (i * 8)) & 255)
return array_list
@staticmethod
def rotate_left(i, i2):
return Sign.circular_shift(i, i2)
@staticmethod
def circular_shift(i, i2):
# 确保 i 是 32 位的无符号整数
i = i & 0xFFFFFFFF
# 计算无符号右移和左移
right_shift = (i >> (32 - i2)) & 0xFFFFFFFF
left_shift = (i << i2) & 0xFFFFFFFF
# 按位或操作得到最终结果
result = right_shift | left_shift
return result
def sign(self, bArr):
padding = self.padding(bArr)
# print(padding)
i, i2, i3, i4 = self.A, self.B, self.C, self.D
for i5 in range(len(padding) // 64):
iArr = [0] * 16
for i6 in range(16):
i7 = (i5 * 64) + (i6 * 4)
iArr[i6] = (
(padding[i7 + 3] << 24) |
(padding[i7 + 2] << 16) |
(padding[i7 + 1] << 8) |
(padding[i7])
)
iArr2 = [0, 4, 8, 12]
i8, i9, i10, i11 = i, i2, i3, i4
for i12 in range(4):
i13 = iArr2[i12]
i8 = self.ff(i8, i9, i10, i11, iArr[i13], 3)
ff = self.ff(i11, i8, i9, i10, iArr[i13 + 1], 7)
i10 = self.ff(i10, ff, i8, i9, iArr[i13 + 2], 11)
i9 = self.ff(i9, i10, ff, i8, iArr[i13 + 3], 19)
i11 = ff
iArr3 = [0, 1, 2, 3]
i14, i15 = i8, i11
for i16 in range(4):
i17 = iArr3[i16]
i14 = self.gg(i14, i9, i10, i15, iArr[i17], 3)
i15 = self.gg(i15, i14, i9, i10, iArr[i17 + 4], 5)
i10 = self.gg(i10, i15, i14, i9, iArr[i17 + 8], 9)
i9 = self.gg(i9, i10, i15, i14, iArr[i17 + 12], 13)
iArr4 = [0, 2, 1, 3]
i18 = i14
for i19 in range(4):
i20 = iArr4[i19]
hh = self.hh(i18, i9, i10, i15, iArr[i20], 3)
i15 = self.hh(i15, hh, i9, i10, iArr[i20 + 8], 9)
i10 = self.hh(i10, i15, hh, i9, iArr[i20 + 4], 11)
i9 = self.hh(i9, i10, i15, hh, iArr[i20 + 12], 15)
i18 = hh
i += i18
i2 += i9
i3 += i10
i4 += i15
return f"{i & 0xFFFFFFFF:02x}{i2 & 0xFFFFFFFF:02x}{i3 & 0xFFFFFFFF:02x}{i4 & 0xFFFFFFFF:02x}"
@staticmethod
def string_to_utf8_byte_string(s):
# 将字符串转换为 UTF-8 编码的字节
utf8_bytes = s.encode('UTF-8')
# 将每个字节转换为整数,并用逗号分隔
byte_string = ','.join(str(b) for b in utf8_bytes)
return byte_string
if __name__ == "__main__":
sign = Sign()
s = sign.string_to_utf8_byte_string("page=31720085906")
sb = ''.join([chr(int(c)) for c in s.split(',')])
result = sign.sign(sb.encode('utf-8'))
print(result)
通关