CTF

[HSCTF 9] ICVC

skyepodium 2022. 6. 6. 10:04

1. 개요

복호화 알고리즘 만드는 문제

 

2. 분석

1) 암호화에 사용되는 코드가 주어집니다.

 

간단하니 이를 거꾸로 동작하도록 만듭니다.

state = 1
flag = "[REDACTED]"
alphabet = "abcdefghijklmnopqrstuvwxyz"
assert(flag[0:5]+flag[-1]=="flag{}")
ciphertext = ""
for character in flag[5:-1]:
    state = (15*state+18)%29
    ciphertext+=alphabet[(alphabet.index(character)+state)%26]
print(ciphertext)

 

3. exploit

# 1. init
ciphertext = "mawhxyovhiiupukqnzdekudetmjmefkqjgmqndgtnrxqxludegwovdcdmjjhw"
alphabet = "abcdefghijklmnopqrstuvwxyz"
flag = ""
state = 1

# 2. loopr
res = ""
for c in ciphertext:
    state = (15 * state + 18 ) % 29

    idx = alphabet.index(c) - state
    if idx < 0: idx += 26
    res += alphabet[idx]

print(res)
# iguessthisiswhatyouwouldcallalinearcongruentialvigenerecipher

 

4. 여담

flag에 vigenere cipher가 언급되어 있는데 알고리즘 판별 사이트에 돌려봐도 가장 유사하게 나옵니다.

 

다만, 일반적으로 비즈네르는 key가 필요한데 문제에서는 state가 그와 유사한 동작을 합니다.

 

비즈네르 암호 구현