picoCTF General Skills Guide

here's how to solve convertme.py

Back to the General Skills Guides

convertme.py

Name: convertme.py
Description: Run the Python script and convert the given number from decimal to binary to get the flag. Download Python script
Author: LT 'syreal' Jones
Tags: Easy, General Skills, Beginner picoMini 2022, base, Python
Challenge from: Beginner picoMini 2022
Files: convertme.py
Hints:
1. Look up a decimal to binary number conversion app on the web or use your computer's calculator!
2. The str_xor function does not need to be reverse engineered for this challenge.
3. If you have Python on your computer, you can download the script normally and run it. Otherwise, use the wget command in the webshell.
4. To use wget in the webshell, first right click on the download link and select 'Copy Link' or 'Copy Link Address'
5. Type everything after the dollar sign in the webshell: $ wget , then paste the link after the space after wget and press enter. This will download the script for you in the webshell so you can run it!
6. Finally, to run the script, type everything after the dollar sign and then press enter: $ python3 convertme.py

Theory

According to the description, to get the flag we have to run a python code, should be easy because it's just passing a number from decimal to binary. Can't do anything else in theory, so let's pass on to there.

Solution

First let's download the code:

import random

def str_xor(secret, key):
    #extend key to secret length
    new_key = key
    i = 0
    while len(new_key) < len(secret):
        new_key = new_key + key[i]
        i = (i + 1) % len(key)        
    return "".join([chr(ord(secret_c) ^ ord(new_key_c)) for (secret_c,new_key_c) in zip(secret,new_key)])

flag_enc = chr(0x15) + chr(0x07) + chr(0x08) + chr(0x06) + chr(0x27) + chr(0x21) + chr(0x23) + chr(0x15) + chr(0x5f) + chr(0x05) + chr(0x08) + chr(0x2a) + chr(0x1c) + chr(0x5e) + chr(0x1e) + chr(0x1b) + chr(0x3b) + chr(0x17) + chr(0x51) + chr(0x5b) + chr(0x58) + chr(0x5c) + chr(0x3b) + chr(0x42) + chr(0x57) + chr(0x5c) + chr(0x0d) + chr(0x5f) + chr(0x06) + chr(0x46) + chr(0x5c) + chr(0x13)

num = random.choice(range(10,101))

print('If ' + str(num) + ' is in decimal base, what is it in binary base?')

ans = input('Answer: ')

try:
  ans_num = int(ans, base=2)
  
  if ans_num == num:
    flag = str_xor(flag_enc, 'enkidu')
    print('That is correct! Here\'s your flag: ' + flag)
  else:
    print(str(ans_num) + ' and ' + str(num) + ' are not equal.')
  
except ValueError:
  print('That isn\'t a binary number. Binary numbers contain only 1\'s and 0\'s')

So it seems that it's gonna ask what a number is in binary like we predicted earlier, now we can do the conversion with python:

If 20 is in decimal base, what is it in binary base?

    >>> print(bin(20))
    0b10100

Answer: 
10100
That is correct! Here's your flag: picoCTF{4ll_y0ur_b4535_722f6b39}

There we go! That's the flag.

I rated this level as "good"! :3


https://play.picoctf.org/practice/challenge/239