[CTF Writeup / Crypto] LA CTF 2024 - valentines day
비즈네르 암호화 문제.
ct.txt에 암호문이 있고, intro.txt에 첫번째 줄의 평문이 적혀있다.
key의 길이는 161글자이므로, 무척 길다. 하지만 알려진 평문의 길이가 거의 130이라서 편리하게 해독할 수 있다.
최종 익스 코드는 다음과 같다.
import string
key = [0 for _ in range(161)]
#### guess key start
p = '''On this Valentine's day, I wanted to show my love for professor Paul Eggert. This challenge is dedicated to him. Enjoy the challenge!'''
c = '''Br olzy Jnyetbdrc'g xun, V avrkkr gb sssp km frja sbv kvflsffoi Jnuc Sathrg. Wkmk gytjzyakz mj jsqvcmtoh rc bkd. Canjc kns puadlctus!'''
start = 0
cnt = 0
for i in range(len(p)):
if p[i].lower() in string.ascii_lowercase:
a = ord(c[i].lower())
b = ord(p[i].lower())
key[start + cnt] = (26 + a - b) % 26
cnt += 1
#### end
assert len(key) == 161
ctpath = 'lactf\crypto-valentines-day\ct.txt'
with open(ctpath) as f:
ct = f.read()
pt = ''
cnt = 0
for c in ct:
if c.lower() in string.ascii_lowercase:
cp = string.ascii_lowercase.index(c.lower())
dp = (26 + cp - key[cnt % len(key)]) % 26
d = string.ascii_lowercase[dp]
pt += d
cnt += 1
else:
pt += c
print(pt)
print(len(string.ascii_lowercase))
댓글
댓글 쓰기