CHReverse

We are given a python file and a output text file

lets inspect them

script.py
flag = 'sctf{REDACTED}'
key = 'THEKEY'
i = 0

encrypted = ''

for char in flag:
    value = ord(char)
    if value < 97:
        value += 32
        value = value ^ ord(key[i])
        encrypted += chr(value)
    else:
        value -= 64
        value = value ^ ord(key[i])
        encrypted += chr(value)
    i += 1
    if i > 5:
        i = 0

print(encrypted)
with open("output.txt", "w") as f:
    f.write(encrypted)

Script

The script does a few things for every character in the flag:

  1. it checks if the ascii value is below 97 or not, and depending on that, it either adds 32 to the ascii value or subtracts 64

  2. it performs an XOR on the new ascii value and an ascii value of a character of the key

  3. it adds the character representation of the final ascii value to a string called encrypted

Additionally, to select which character of the key to use, the program goes through the following selection process:

which means that it iterates through every value and resets back to the first character when it reaches the last character

e.g

Reversing the script

flag:

sctf{r3v3rsing_th3_c0d3}

Last updated