Skip to content

Instantly share code, notes, and snippets.

@sonickun
Created October 5, 2016 10:39
Show Gist options
  • Select an option

  • Save sonickun/580e97bf9abe60f68da3ef201f379ece to your computer and use it in GitHub Desktop.

Select an option

Save sonickun/580e97bf9abe60f68da3ef201f379ece to your computer and use it in GitHub Desktop.
Tokyo Westerns CTF 2016 | Super Express (Crypto100)
import itertools
cipher = '805eed80cbbccb94c36413275780ec94a857dfec8da8ca94a8c313a8ccf9'
for i, j in itertools.product(range(251), repeat=2):
if (ord("T")*i+j)%251==0x80 and (ord("W")*i+j)%251==0x5e:
a, b = i, j
break
print a, b
flag = ''
for i in range(0, len(cipher), 2):
m = int(cipher[i:i+2], 16)
for i in range(0x20,0x7f):
if (i*a+b)%251 == m:
flag += chr(i)
print flag
# flag: TWCTF{Faster_Than_Shinkansen!}
@sonickun
Copy link
Copy Markdown
Author

sonickun commented Oct 5, 2016

鍵を使って平文を一文字ずつ変換していく換字式暗号。鍵の長さに応じて変換の回数が変化するが、変換は線形写像であり、何度繰り返しても同じ形の式になるので、高々1回分の鍵のパターンを当てるのと同じ難易度。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment