๋ฐ์ํ
One-Time Pad
One-Time Pad ๋ ์ผํ์ฑ ํจ๋๋ฅผ ์ด์ฉํ์ฌ ๋ณด์๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ์ํธ ์์คํ ์ด๋ค. ํ๋ฌธ๊ณผ ํค์ ๊ธธ์ด๊ฐ ์๋ก ๋์ผํด์ผ ํ๋ฉฐ, ํค๋ ๋จ ํ๋ฒ๋ง ์ฌ์ฉ๋์ด์ผ ํ๋ค. ์ํธํ ๊ณผ์ ์์ ํ๋ฌธ๊ณผ ํค ๊ฐ์ XOR ์ฐ์ฐ์ ์ฌ์ฉํ๋ค.
๋ฌธ์ ํด์
- flag_enc = FLAG ^ key
- FLAG ๊ฐ์ ์ฝ์ด์์ key ์ xor ํ ํ flag_enc ๋ฅผ ์ถ๋ ฅํ๋ค.
- new_key = key ^ rand_bit
- key์ ๋ฌด์์ํ bit์ด์ ๋ํด์ ์๋ก์ด ํค๋ฅผ ์์ฑํ๋ค. ์ด๋, rand_bit์ ๊ธธ์ด๊ฐ 64byte์ด๋ฏ๋ก new_key์ ๊ธธ์ด๋ 64byte์ ๊ทผ์ ํ ๊ฒ์ด๋ผ ์ถ์ธกํ ์ ์๋ค.
- input_enc = {input} ^ new_key
- ์ฐ๋ฆฌ๊ฐ ์ ๋ ฅํ ๊ฐ์ ์๋ก์ด ํค๋ฅผ xor ํ์ฌ ์ํธํ๋ ๊ฐ์ ์ถ๋ ฅํ๋ค. input์ ๊ธธ์ด ๋งํผ๋ง key๋ฅผ ์๋ผ์ ์ฌ์ฉํ๋ ์ฝ๋๊ฐ ์กด์ฌํ๋ฏ๋ก input์ ๋ฃ์ ์ ์๋ ์ต๋ ๊ธธ์ด๋ฅผ ๋ฃ๋๋ก ํ๋ค.
์๋ฒ ์คํ
flag_enc: 0b10100000100111011101010101011110 ...
Plain text : 0000000000000000000000000000000000000000000000000000000000000000
input_enc: 3346417034361305867439072305201355648991850274910930070918752521983423720001914392514304897965851295662176779195519267721152888101451266383436211583479274
ํ์ด ์ฝ๋
๋ฌธ์ ํด์ ๋จ๊ณ์ ์ฐ์ฐ์ ๊ฑฐ๊พธ๋ก ์ฌ๋ผ๊ฐ๋ค๋ณด๋ฉด FLAG ๊ฐ์ ๊ตฌํ ์ ์๋ค.
# input ํ๋ฌธ
input_txt = '0000000000000000000000000000000000000000000000000000000000000000'
input_enc = 3346417034361305867439072305201355648991850274910930070918752521983423720001914392514304897965851295662176779195519267721152888101451266383436211583479274
flag_enc = 0b10100000010011101110101010101111011111100010001011101001111100000001010001000100010101111001101111010011111001011100111011000001001011010011011010100000000011010110001010101011101100000000100001100110010011100110100110010110111010110001100101111111001101111111010101010100001011110011001001000010011101000010001000000110001111101011000111101001001101001011111010000010110001011111001101110101000110110011000001110000100111110100011001100010011011000100010001011100010000111100000110110011101010011100001000010010
# input์ ์ด์ง์๋ก ๋ณํ
binary_list = ['0b']
for ch in input_txt:
binary_list.append(format(ord(ch), 'b').zfill(8))
binf = "".join(binary_list)
# 3. new_key = input ^ input_enc
new_key = int(binf, 2) ^ input_enc
# 2. key = new_key ^ rand_bit
old_key = bin(new_key ^ 0b10010110101011100100111011100101101011110011001110000101111010111110010111100000111110000000010101101011001100010100010101111000111111100010001010110000010111110111110010001111110011110101001011111010100101010100001110010111111010001101111110011001010110011001010101010000001010100000101101001010010010100010100001011101011011010011010101111111010010100111011001100000101011100001010111111101000110011000110101111111010111001101111110011101101100011101001111111000010011010111100010111001100101011111101111111001)
# 1. FLAG = key ^ flag_enc
flag_bin = bin(int(old_key, 2) ^ flag_enc)[2:]
# flag_bin์ ์์ 0์ด ์๋ต ๋์์ ์ ์์ผ๋ฏ๋ก 8์ ๋๋ ๋๋จธ์ง ์ฐ์ฐ
remainder = (len(flag_bin)) % 8
print(chr(int(flag_bin[0:remainder], 2)), end='')
flag_binary = [chr(int(flag_bin[i:i+8], 2)) for i in range(6, len(flag_bin), 8)]
FLAG = "".join(flag_binary)
print(FLAG)
๋ฐ์ํ
'๐ดโโ ๏ธ CTF ๐ดโโ ๏ธ > ๐งฎ ์ํธํ ๐งฎ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Dream Hack - Crypto] Pyploit (2) | 2023.12.18 |
---|---|
[Dream Hack - Crypto] [LINE CTF 2021] babycrypto1 (2) | 2023.12.12 |
[Dream Hack - Crypto] likeb64 (0) | 2023.12.09 |
[DreamHack - Crypto] uncommon_e (2) | 2023.11.22 |
[Dream Hack - Pwnable] baby-bof (0) | 2023.11.19 |