1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| import time def fand(a, b): if a == '1': if b == '1': return '1' return '0' def f_or(a, b): if a == '0': if b == '0': return '0' return '1' def frev(a): if a == '1': return '0' if a == '0': return '1' def fxor(a, b): return f_or(fand(a, frev(b)), fand(frev(a), b)) def f5(x, y, z): s = fxor(fxor(x, y), z) c = f_or(fand(x, y), fand(z, f_or(x, y))) return (s, c) def fadd(a, b): ans = '' z = '0' a = a[::-1] b = b[::-1] for i in range(32): ans += f5(a[i], b[i], z)[0] z = f5(a[i], b[i], z)[1] return ans[::-1] def fshl(a, n): return a[n:] + '0' * n def fshr(a, n): return n * '0' + a[:-n] def fxor_int(a, b): ans = '' for i in range(32): ans += fxor(a[i], b[i]) return ans def TEA_encrypt(v0, v1, k0, k1, k2, k3): s = '00000000000000000000000000000000' d = '10011110001101110111100110111001' for i in range(32): s = fadd(s, d) v0 = fadd(v0, fxor_int(fxor_int(fadd(fshl(v1, 4), k0), fadd(v1, s)), fadd(fshr(v1, 5), k1))) v1 = fadd(v1, fxor_int(fxor_int(fadd(fshl(v0, 4), k2), fadd(v0, s)), fadd(fshr(v0, 5), k3))) return v0 + v1 k0 = '0100010001000101'.zfill(32) k1 = '0100000101000100'.zfill(32) k2 = '0100001001000101'.zfill(32) k3 = '0100010101000110'.zfill(32) flag = input('please input flag:') if flag[0:7] != 'SUSCTF{' or flag[-1] != '}': print('Error!!!The formate of flag is SUSCTF{XXX}') time.sleep(5) exit(0) flagstr = flag[7:-1] if len(flagstr) != 24: print('Error!!!The length of flag 24') time.sleep(5) exit(0) else: res = '' for i in range(0, len(flagstr), 8): v0 = flagstr[i:i + 4] v0 = bin(ord(flagstr[i]))[2:].zfill(8) + bin(ord(flagstr[i + 1]))[2:].zfill(8) + bin(ord(flagstr[i + 2]))[2:].zfill(8) + bin(ord(flagstr[i + 3]))[2:].zfill(8) v1 = bin(ord(flagstr[i + 4]))[2:].zfill(8) + bin(ord(flagstr[i + 5]))[2:].zfill(8) + bin(ord(flagstr[i + 6]))[2:].zfill(8) + bin(ord(flagstr[i + 7]))[2:].zfill(8) res += TEA_encrypt(v0, v1, k0, k1, k2, k3) if res == '001111101000100101000111110010111100110010010100010001100011100100110001001101011000001110001000001110110000101101101000100100111101101001100010011100110110000100111011001011100110010000100111': print('True') else: print('False') time.sleep(5)
|