安全矩阵

 找回密码
 立即注册
搜索
查看: 2155|回复: 0

H4ckIT CTF 2016 : ninja-scheme-195

[复制链接]

5

主题

40

帖子

215

积分

中级会员

Rank: 3Rank: 3

积分
215
发表于 2020-3-30 20:26:00 | 显示全部楼层 |阅读模式
本帖最后由 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:




  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. def slice(s,size):
  4. return [s[i:i+size] for i in range(0,len(s),size)]
  5. #print slice("abcdefghijklmnop",4)
  6. #['abcd'.'efgh','ijkl','mnop']
  7. def xor(a,b):
  8. return "".join([chr(ord(a[i]) ^ ord(b[i%len(b)])) for i in xrange(len(a))])
  9. #print xor('AAAABBBB','11112222')
  10. #pppppppp
  11. def f(L,n):
  12. ans = ""
  13. for i in range(len(L)):
  14. ans += chr((ord(L[i]) + n) % 256)
  15. return ans
  16. def decrypt(cipher,rounds):
  17. assert len(cipher) == 8
  18. r = cipher[4:]
  19. l = cipher[:4]
  20. tmp = l
  21. l = r
  22. r = tmp
  23. for n in reversed(range(1,rounds + 1)):
  24. tmp = l
  25. l = r
  26. r = xor(tmp,f(r,n))
  27. return l + r
  28. cipher = "dd67ca82d358f0c8479e118addcec2f8ce086c0f6f239f9b66d7226a38c68198dbd777f366fb9fd83b60d11109be174759c75ea56a4866c2"
  29. cipher = slice(cipher.decode("hex"),8)
  30. for i in range(1000):
  31. plain = decrypt(cipher[0],i)
  32. if plain.find("h4ck1t") >= 0:
  33. print "rounds = ",i
  34. rounds = i
  35. flag = ""
  36. for c in cipher:
  37. flag += decrypt(c,rounds)
  38. print flag
复制代码




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-4-20 19:34 , Processed in 0.012272 second(s), 19 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表