picoCTF 2022 | basic-mod1 & basic-mod2 Write-up

basic-mod1:

Challenge description

We found this weird message being passed around on the servers, we think we have a working decrpytion scheme. Download the message here. Take each number mod 37 and map it to the following character set: 0-25 is the alphabet (uppercase), 26-35 are the decimal digits, and 36 is an underscore. Wrap your decrypted message in the picoCTF flag format (i.e. picoCTF{decrypted_message})

Category: Cryptography

Solution

We start this challenge by viewing the encoded message:

Just a string of numbers

According to the challenge description, we have to next take these numbers, mod them by 37, and match them to a character set. I threw together a quick python script to get this done:

import string

# First I make a list out of the encoded message
ctxt = "128 63 242 87 151 147 50 369 239 248 205 346 299 73 335 189 105 293 37 214 333 137".split()
ptxt = ""

# Next, I will create the decrypting scheme, following the challenge's description
# This will be the uppercase letters from A-Z, decimal digits from 0-9, and then the underscore
decrypt = list(string.ascii_uppercase) + list (string.digits) + ["_"]

charcode = 0
for num in ctxt:
    charcode = int(num) % 37 # Take the numbers and mod them by 37, as the challenge stated
    ptxt = ptxt + decrypt[charcode] # Taking the result and referencing the decrypting scheme to get the plaintext

print("picoCTF{" + ptxt + "}") # Turning the output into the correct flag format

Simply run this to get the flag:

basic-mod2:

Challenge description

A new modular challenge! Download the message here. Take each number mod 41 and find the modular inverse for the result. Then map to the following character set: 1-26 are the alphabet, 27-36 are the decimal digits, and 37 is an underscore. Wrap your decrypted message in the picoCTF flag format (i.e. picoCTF{decrypted_message})

Category: Cryptography

Solution

This is essentially the same as basic-mod1. I reused the same python script, with a few modifications. There are, however, an extra step:

First, finding the inverse modulo

I’m not too familiar with the mathematical function but there is an easy explanation of how to calculate it using python (link)

And since this operation won’t result in a “0” in this challenge, I just added a random padding element to the start of the list so that it starts indexing from 1 instead of 0:

import string

# First I make a list out of the encoded message
ctxt = "186 249 356 395 303 337 190 393 146 174 446 127 385 400 420 226 76 294 144 90 291 445 137 ".split()
ptxt = ""

# Next, I will create the decrypting scheme, following the challenge's description
# This will be the uppercase letters from A-Z, decimal digits from 0-9, and then the underscore
# I added a padding element at the start of the decrypting scheme because "charcode" cannot be 0 in this challange
decrypt = ["Padding"] + list(string.ascii_uppercase) + list (string.digits) + ["_"]

charcode = 0
for num in ctxt:
    charcode = pow((int(num) % 41), -1, 41) # Take the numbers and mod them by 41, as the challenge stated8
    ptxt = ptxt + decrypt[charcode] # Taking the result and referencing the decrypting scheme to get the plaintext

print("picoCTF{" + ptxt + "}") # Turning the output into the correct flag format

And we got the flag:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: