Random Encoder 3

Oh. My. Goodness.

We are given the following script to reverse

import random as r
r.seed("can_you_solve_this???_1234567890!@#$%^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM")

flag = "GCTF24{FLAG_REMOVED}"

encoded = ""
for i in flag:
    a = i
    for x in range(r.randint(1, 10)):
        case = r.randint(1, 10)
        if case == 1:
            a = a.swapcase() if r.randint(1, 2) == 1 else a
        elif case == 2:
            a = chr(ord(a) + r.randint(10, 20))
        elif case == 3:
            a = chr(ord(a) - r.randint(10, 20))
        elif case == 4:
            a = chr(ord(a) * r.randint(1, 3))
        elif case == 5:
            a = chr(ord(a) * r.randint(1, 2) - r.randint(25, 50))
        elif case == 6:
            a = chr(ord(a) + r.randint(1, 2))
        elif case == 7:
            a = chr(ord(a) + r.randint(25, 50))
        elif case == 8:
            a = chr(ord(a) + r.randint(200, 300))
        elif case == 9:
            a = chr(ord(a) + r.randint(-10, 10))
        elif case == 10:
            None
    encoded += a
print(encoded) # Flag is ϕż=¦ý<R8dijՊ¼{ijɁċkËIdΤŃƠnD͇෗^Ių̔JOʐƠĽ̰ŲfªŮƅ

First, lets try to understand this script.

Key Components

  • Process Each Character of the flag

  • Apply a Random Number of Transformations

  • Perform Transformations Based on case

  • Depending on the value of case, a specific transformation is applied to a:

    • Case 1: Randomly swaps the case (uppercase ↔ lowercase) with a 50% chance.

    • Case 2: Adds a random value (10 to 20) to the ASCII value of the character.

    • Case 3: Subtracts a random value (10 to 20) from the ASCII value of the character.

    • Case 4: Multiplies the ASCII value by a random factor (1 to 3).

    • Case 5: Applies a more complex transformation by multiplying and then subtracting a random value (25 to 50).

    • Case 6: Adds a small random value (1 to 2) to the ASCII value.

    • Case 7: Adds a large random value (25 to 50) to the ASCII value.

    • Case 8: Adds an even larger random value (200 to 300) to the ASCII value.

    • Case 9: Adds a small random shift (-10 to 10) to the ASCII value.

    • Case 10: Does nothing (None).

  • Output

Solve script

Output

Thus the flag is GCTF24{w0W_tH@T_chalL3Ng3_W4$_t0O_T3d!0Us}

Last updated