|
本帖最后由 ethereel 于 2020-3-30 20:27 编辑
题目内容:
General Tompson welcomes you...again! We have some crypto-problem here...again. Our scouts have intercepted this enemy cryptogram: dd67ca82d358f0c8479e118addcec2f8ce086c0f6f239f9b66d7226a38c68198dbd777f366fb9fd83b60d11109be174759c75ea56a4866c2 Some time later our IT-ninjas have broken into the enemy computer system and grabbed something pretty much similar to undefined encryption algorithm scheme. Look at this grabbed scheme and help us to understand how it works. Yours, Gen. Tompson
writeup:
- #!/usr/bin/env python
- # coding=utf-8
- def slice(s,size):
- return [s[i:i+size] for i in range(0,len(s),size)]
- #print slice("abcdefghijklmnop",4)
- #['abcd'.'efgh','ijkl','mnop']
- def xor(a,b):
- return "".join([chr(ord(a[i]) ^ ord(b[i%len(b)])) for i in xrange(len(a))])
- #print xor('AAAABBBB','11112222')
- #pppppppp
- def f(L,n):
- ans = ""
- for i in range(len(L)):
- ans += chr((ord(L[i]) + n) % 256)
- return ans
- def decrypt(cipher,rounds):
- assert len(cipher) == 8
- r = cipher[4:]
- l = cipher[:4]
- tmp = l
- l = r
- r = tmp
- for n in reversed(range(1,rounds + 1)):
- tmp = l
- l = r
- r = xor(tmp,f(r,n))
- return l + r
- cipher = "dd67ca82d358f0c8479e118addcec2f8ce086c0f6f239f9b66d7226a38c68198dbd777f366fb9fd83b60d11109be174759c75ea56a4866c2"
- cipher = slice(cipher.decode("hex"),8)
- for i in range(1000):
- plain = decrypt(cipher[0],i)
- if plain.find("h4ck1t") >= 0:
- print "rounds = ",i
- rounds = i
- flag = ""
- for c in cipher:
- flag += decrypt(c,rounds)
- print flag
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|