B007L36 CRYP70... 4641N

Alright so this is basically obscurity crypto.

A little experimentation shows us that it for every byte of the plaintext and the matching byte of the key it adds the ascii values and then moduluses them by 256.

NOTE: because of how python .encode and decode works, for example, '\x7f'.encode() = b'\xc2\x7f'.

So, whenever we base 64 decode, we have to .decode().encode('latin-1') to get the proper byte values instead of weird UTF-8 ones.

It's possible to use modular arithmetic to get the key, in fact that probably wouldn't have been much harder, but instead I just ran a small byte by byte brute force of each char of the key, and then the flag, as this is a character by character cipher making it vulnerable to such an attack.

My script is below:

plain = b"To test the encryption service, encrypt this file with your company issued secret key and ensure that it results in the ciphertext.txt file."
import base64
enc = base64.b64decode(b"w4bDkMKDw6jDi8Ouw6JQw6jDh8OZwojCmMONw4nDnsKtwqnDk8OiwqLDosKdw6XDhsOVw6rDj8Oew5NcwpTDhMOiw4vCpcOYw5bDoFTCrcOHw6LCpsKUw6PDm8ONw4jClMOdw6TDosKYwpTDmMOjw53CpX/DicObwqHCqcOAw6fCrMKUw6bDpcOUw5jDmcOKwpvDocKVw5fDkcOZw5xTw4rDi8OlVMKaw43DnVPDmcOrw6XDlsOVw5nChsOvw5bCkcOof8Odw5xTw5HDi8OfwqnCpcOTw6xTw53Dq8KSw5XDi8OZwobDnsOXwqDDnMOEw6bDnMKYw5fDmsKawqjCscOTwpnCmcOdw6nDl8KP").decode().encode('latin-1')
def encrypt(num,key):
    return (num + key) % 256
key = b""
for char in range(len(enc)):
    for possible in range(256):
        if enc[char] == encrypt(plain[char],possible):
            key += bytes([possible])
            break
print(key)
flagenc = base64.b64decode(b"w6TDgsOGw6jDjMO2w5RgwqTDi8OTw5Vmwr7CncOjZcKcwpLDmGjDnMKxw5/ClMOCwqTDlMOaw5tjw7E=").decode().encode('latin-1')
flag = b""
for char in range(len(flagenc)):
    for possible in range(256):
        if flagenc[char] == encrypt(possible,key[char]):
            flag += bytes([possible])
            break
print(flag)

Flag:ractf{f00l_m3_7w1c3_5h4m3_0n_m3}

Last updated