๋ฐ์ํ
ํ์ด ๊ณผ์
1. enc ํจ์์์ q ๊ฐ์ ๋ค์๊ณผ ๊ฐ์ ์์ ๋ง์กฑํ๋ค.
2. n = 3, key2 = 95 ์ผ๋, q = -200640142664324295933714 ์ ๋ง์กฑํ๋ p, key1 ์ ๊ตฌํ์!
3. key1 < key2 ์ด๋ฏ๋ก 0 ≤ key1 < 95 ์ด๊ณ , ์์์ key1 ๊ฐ์ ๋ํ p ๊ฐ์ ํ์ธํ์ฌ flag๋ฅผ ์ถ๋ก ํ์!!
4. p ๊ฐ์ ํ์ธํ๋ dec ํจ์๋ ๋ค์๊ณผ ๊ฐ์ ์์ ๋ง์กฑํ๋ค.
5. dec ๋ฅผ ํตํด p ๋ฅผ ๊ตฌํ๊ณ , enc ์ p ๋ฅผ ๋์ ํ์ฌ q_test ๊ตฌํ ํ ๊ธฐ์กด p ๊ฐ๊ณผ ๋น๊ตํ๋ค.
ํ์ด ์ฝ๋
import random
from fractions import Fraction
# ์ฃผ์ด์ง ๊ฐ p๋ฅผ n, key1, key2๋ฅผ ์ฌ์ฉํ์ฌ ์ํธํํ๋ ํจ์
def enc(p, n, key1, key2):
q = (Fraction(p, n+1)*key1**(n+1)) - (Fraction(p, n+1)*key2**(n+1))
print("[OK] plain is encrypted : ", q)
return q
# ์ํธํ๋ ๊ฒฐ๊ณผ q๋ฅผ ๋ณตํธํํ๋ ํจ์ (์ฝ๋ ๋ด์ฉ์ด ๋๋ฝ๋์ด ์์)
def dec(q, n, key1, key2):
temp = key1**(n+1) - key2**(n+1)
p = int((n+1) * q / temp)
print("[OK] cipher is decrypted : ", p)
return p
# n, key1, key2๋ฅผ ๋๋คํ๊ฒ ์์ฑ
n, key2 = 3, 95
q = -200640142664324295933714
# ๋ธ๋ฃจํธ ํฌ์ค๋ก ์๋ฏธ ์๋ ๋ฌธ์์ด์ด ๋์ฌ ๋๊น์ง ์คํญ์ ์์ผ๋ณด์!!
for key in range(0,95) :
p = dec(q, n, key, key2)
print("key : ", key)
q_test = enc(p, n, key, key2)
if q_test == q :
print("p : ", p)
print("YEAH!!!!! here!!!!!")
break
์คํ ๊ฒฐ๊ณผ
flag๋ DH{10112210997116104} ์ด๋ค. ์์คํค ์ฝ๋๋ฅผ ๋ณํํด๋ณด๋ ezmath๋ผ๊ณ ํ๋ค!!ใ ใ
๋ฐ์ํ
'๐ดโโ ๏ธ CTF ๐ดโโ ๏ธ > ๐งฎ ์ํธํ ๐งฎ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Dream Hack - Crypto] fuzzy flag (0) | 2023.09.04 |
---|---|
[Dream Hack - Crypto] chinese what? (0) | 2023.09.04 |
[Dream Hack - Crypto] darimchal_001 (0) | 2023.09.04 |
[Dream Hack - Crypto] ROT128 (0) | 2023.09.04 |
[Dream Hack - Crypto] Robot Only (0) | 2023.09.02 |