pyc文件。
文件头有问题。修改一下文件头,然后编译成py文件
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
|
from ctypes import * from Crypto.Util.number import bytes_to_long from Crypto.Util.number import long_to_bytes
def encrypt(v, k): v0 = c_uint32(v[0]) v1 = c_uint32(v[1]) sum1 = c_uint32(0) delta = 195935983 for i in range(32): v0.value += (v1.value << 4 ^ v1.value >> 7) + v1.value ^ sum1.value + k[(sum1.value & 3)] sum1.value += delta v1.value += (v0.value << 4 ^ v0.value >> 7) + v0.value ^ sum1.value + k[(sum1.value >> 9 & 3)]
return ( v0.value, v1.value)
if __name__ == '__main__': flag = input('please input your flag:') k = [255, 187, 51, 68] if len(flag) != 32: print('wrong!') exit(-1) a = [] for i in range(0, 32, 8): v1 = bytes_to_long(bytes(flag[i:i + 4], 'ascii')) v2 = bytes_to_long(bytes(flag[i + 4:i + 8], 'ascii')) a += encrypt([v1, v2], k)
enc = [ 4006073346, 2582197823, 2235293281, 558171287, 2425328816, 1715140098, 986348143, 1948615354] for i in range(8): if enc[i] != a[i]: print('wrong!') exit(-1)
print('flag is flag{%s}' % flag)
|
1 2 3 4 5
| for i in range(0, 32, 8): v1 = bytes_to_long(bytes(flag[i:i + 4], 'ascii')) v2 = bytes_to_long(bytes(flag[i + 4:i + 8], 'ascii')) a += encrypt([v1, v2], k)
|
这个代码就是把flag拆分一下。
for i in range(32):
v0.value += (v1.value << 4 ^ v1.value >> 7) + v1.value ^ sum1.value + k[(sum1.value & 3)]
sum1.value += delta
v1.value += (v0.value << 4 ^ v0.value >> 7) + v0.value ^ sum1.value + k[(sum1.value >> 9 & 3)]
这里是一个类似于tea加密的方式。【但不是tea】
先将flag,char类型化成2个int类型为一组的数据。然后将2个int类型的数据进行tea加密。
解密:将2个int类型的数据进行解密,得到2个解密后的int类型,再将他转化成char类型。
解密:
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
|
int main() { u_int enc[] = { 4006073346, 2582197823, 2235293281, 558171287, 2425328816, 1715140098, 986348143, 1948615354 }; u_int k[] = { 255, 187, 51, 68 }; for (int i = 0; i < 8; i += 2) { u_int delta = 195935983; u_int s1 = delta * 32; //因为加密代码中 是+了32次,这里需要--,所以就先*32 for (int j = 0; j < 32; j++) { enc[i + 1] -= (enc[i] << 4 ^ enc[i] >> 7) + enc[i] ^ s1 + k[s1 >> 9 & 3]; s1 -= delta; enc[i] -= (enc[i + 1] << 4 ^ enc[i + 1] >> 7) + enc[i + 1] ^ s1 + k[s1 & 3]; } } char flag[32] = { 0 }; for (int i = 0; i < 8; i++) {//下面是int类型转成char类型 flag[4 * i] = enc[i] >> 24; flag[4 * i + 1] = (enc[i] >> 16) ^ 0xFF000000; flag[4 * i + 2] = (enc[i] >> 8) ^ 0xFF000000; flag[4 * i + 3] = enc[i] ^ 0xFF000000; } for (int i = 0; i < 32; i++) { printf("%c", flag[i]); } }
|