Cryptography

Challenge
Link

Unique Flag (109 pts)

Complicated Function (117 pts) UPSOLVE

Unique Flag (109 pts)

Description

I heard unique flag makes problems good.

Solution

Given source code below

from Crypto.Util.number import getPrime

p = getPrime(1024)
q = getPrime(1024)
N = p * q
e = 0x10001

with open('flag.txt', 'rb') as f:
    flag = f.read()

assert len(flag) == 33

flag_header = flag[:7] # TSGCTF{
flag_content = flag[7:-1]
flag_footer = flag[-1:] # }

assert len(flag_content) == len({byte for byte in flag_content}) # flag_content is unique

c_list = [pow(byte, e, N) for byte in flag]
clues = [x * y % N for x, y in zip(c_list[:-1], c_list[1:])]
clues.sort()

print(f'N = {N}')
print(f'e = {e}')
print(f'clues = {clues}')

So we have N, e, and clues. Clues consist of multiplication of consecutive ciphertext for each byte. Here is the detail

  • clues[0] = (pow(input[0], e, N) * pow(input[1], e, N)) % N

  • clues[1] = (pow(input[1], e, N) * pow(input[2], e, N)) % N

Next, clues will be sorted so we dont know the order of the original clues. Since we know part of flag (header) we can do bruteforce recursively to find the flag. Here is the flow

  • Generate ciphertext for each printable char

  • Do multiplication for 2 ciphertext and check if it is available on clues array

  • If the founded plaintext length is 33 , print the plaintext

Flag : TSGCTF{OK,IsTHi5A_un1qUe-flag?XD}

Complicated Function (117 pts)

Description

Solution

Last updated