picoCTF 2022: Cryptography: basic-mod1

picoCTF 2022: Cryptography: basic-mod1

ยท

2 min read

Introduction

Challenge: basic-mod1

Category: Cryptography

Description: We found this weird message being passed around on the servers, we think we have a working decryption 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})

Solution

Here the problem is that we have a message that looks like this:

91 322 57 124 40 406 272 147 239 285 353 272 77 110 296 262 299 323 255 337 150 102

Our goal is to decrypt. To do this we have to follow these steps:

  1. Take each number mod 37: If you don't know what mod 37 means. It means the reminder that we get after dividing the following number by 37. For example, 91 mod 37 will be 17. And we need to do this step for each number
  2. Map it with the character set: After we have got the following number mod 37. We have to map it to the following character set like this: 0-25 is the alphabet (uppercase), 26-35 are the decimal digits, and 36 is an underscore. For example, 17 will be R starting from 0.
  3. Wrap it in picoCTF flag format: Once we have decrypted our message. We have to wrap it in the picoCTF flag format like this: picoCTF{decrypted_message}

Doing this manually is not a good solution so let's write a Python and JavaScript script to do all these steps to decrypt this message.

Python:

import string
characters = string.ascii_uppercase
characters += "0123456789_"

flag_enc = [91,322,57,124,40,406,272,147,239,285,353,272,77,110,296,262,299,323,255,337,150,102]
flag = ""
for char in flag_enc:
    mod = char % 37
    flag += characters[mod]

print('picoCTF{%s}' % flag)

JavaScript:

const characterCodes = Array.from(Array(26)).map((e, i) => i + 65);
let characters = characterCodes.map((x) => String.fromCharCode(x));
characters = [...characters, ...Array.from(Array(10).keys()), "_"]

const flagEnc = [91,322,57,124,40,406,272,147,239,285,353,272,77,110,296,262,299,323,255,337,150,102]
let flag = ""
flagEnc.forEach(char => {
    const mod = char % 37
    flag += characters[mod]
})
console.log(`picoCTF{${flag}}`)

In both programs, the basic thing that is happening is we are creating a list of characters then mapping the mod 37 and adding the letter to the flag string. After that just print it.

If you are on your browser reading this article. Just press CTRL+Shift+J to open the Browser Console and then just paste the above JavaScript code to decrypt this message.

Conclusion

Again, This is a very simple message that we need to decrypt using a very simple decryption scheme.

Flag: picoCTF{R0UND_N_R0UND_ADD17EC2}

Did you find this article valuable?

Support Nouman Rahman by becoming a sponsor. Any amount is appreciated!

ย