DEV Community

wireless90
wireless90

Posted on

2 1

IvyFinal CTF (Crypto 1) - Warmup 50 points

You can get the file here.

Warmup - 50 points

It's important to warmup before physical activity.

Free hint, don't get used to it: XOR cipher was used for this flag's encryption with a single byte key.

Let's Begin

So we practically need to find the key that was xored. Since its just 1 byte, its easy to bruteforce.

And the flag is always in the format if ivyctf{...}.

So lets find the key that simply xors to match the first letter i.

In [19]: def get_key(contents):
    ...:     for i in range(256):
    ...:         if ord(contents[0]) ^ i == ord('i'):
    ...:             return i
    ...:
    ...:
    ...:
    ...:
    ...:
Enter fullscreen mode Exit fullscreen mode

Above is just a function that gets the content of the file and goes through the value of a byte, 0 to 255.
For each of the value, we xor it with the first letter and see if it hits the letter i.

Once we get the key, we simply xor it with the rest of the file.

In [21]: def crack_flag(contents, key):
    ...:     flag = []
    ...:     for ch in contents:
    ...:         flag.append(chr(ord(ch) ^ key))
    ...:     print(''.join(flag))
Enter fullscreen mode Exit fullscreen mode

Once we get our functions right, lets run them.

In [23]: contents = open('flag.enc', 'r').read()

In [24]: crack_flag(contents, get_key(contents))
ivyctf{all_warmed_up_and_ready_to_go}
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay