We start by downloading the encrypted message.
We notice the string
The challenge description says "Let's test your knowledge on Caesar's methods".
This means that the encrypted message is probably encrypted using the Caesar cipher.
To calculate the offset we can use our knowledge of the flag format. Because
Then we use this small python script to decrypt the caesar cipher:
def caesar_cipher(shift: int, file_path: str) -> str:
with open(file_path, 'r') as f:
text = f.read()
result = ''
for char in text:
if char.isalpha():
if char.isupper():
result += chr((ord(char) + shift - 65) % 26 + 65)
else:
result += chr((ord(char) + shift - 97) % 26 + 97)
else:
result += char
return result
shift = int(input("Enter shift: "))
file_path = input("Enter file path: ")
print(caesar_cipher(shift, file_path))
We enter the shift (
We again start by downloading the encrypted message.
We notice the string
The challenge descryption says
This means that the encrypted message is probably encrypted using the Vigenère cipher with the key
Let's try to decrypt the message with python:
def vigenere_cipher(file_path: str) -> str:
with open(file_path, 'r') as f:
text = f.read()
result = ''
password = 'caesar'
i = 0
for char in text:
shift = ord('a') - ord(password[i % len(password)])
if char.isalpha():
if char.isupper():
result += chr((ord(char) + shift - 65) % 26 + 65)
else:
result += chr((ord(char) + shift - 97) % 26 + 97)
i += 1
else:
result += char
return result
file_path = input("Enter file path: ")
print(vigenere_cipher(file_path))
We enter the file path to the encrypted message and get the message with flag:
As always we start by downloading the encrypted message.
The challenge description says
This suggest that the message is encrypted using a Substitution cipher.
We will use a simple Python script to figure out the alphabet mapping:
def cipher(file_path: str) -> str:
with open(file_path, 'r') as f:
text = f.read()
result = ''
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
change = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for char in text:
if char in alphabet:
result += change[alphabet.index(char)]
else:
result += char
return result
file_path = input("Enter file path: ")
print(cipher(file_path))
As you can see we start with a mapping of the alphabet to itself. We will now replace the letters in the
Let's start by looking at
After running the script again the message will get more readable.
We wil now try to figure out more words. For example we notice that
After iterating over the message a few times we get the following mapping:
def cipher(file_path: str) -> str:
with open(file_path, 'r') as f:
text = f.read()
result = ''
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
change = 'FCKHOSMYBVQUPLRTNIAJGEZWXD'
for char in text:
if char in alphabet:
result += change[alphabet.index(char)]
else:
result += char
return result
file_path = input("Enter file path: ")
print(cipher(file_path))
If we run the script again we get the message with flag:
Once again we start by downloading the encrypted message.
The challenge description hints the used cipher:
You can find more information about Transposition ciphers on Wikipedia.
We assume this message is encrypted using the general principle of a transposition cipher:
Write the message in a grid with a given number of columns. Reorder the columns by a given key. Read the message by going through the columns from left to right and from top to bottom.
To reverse this process we have to figure out the number of columns used. If we count the number of characters in the message we get
We will use this simple Python script to write the message into a grid column by column:
def read_file(file_path: str) -> str:
with open(file_path, 'rb') as f:
# read special characters
text = f.read().decode('utf-8')
return text
def getcolumns(text: str, columns: int) -> str:
result = ''
rows = [''] * (len(text)//columns)
for i in range (len(text)//columns):
for j in range (columns):
rows[i] += text[i + j * (len(text)//columns)]
for row in rows:
result += row + '\n'
return result
file_path = input("Enter file path: ")
print(getcolumns(read_file(file_path), 6))
We get the following grid:
rsTapn
sioiot
␣pnchi
raesr␣
␣teay␣
efp␣␣o
nyecpr
i␣toan
gilotr
mhh␣at
␣rtwko
␣␣sbry
aaernr
i␣gntg
erh␣do
rfe␣␣o
hacacr
e␣tris
␣pnal␣
ieanxt
␣stmse
g␣aeU.
leni␣k
utsbis
uottni
ch␣iep
swr,h␣
crihe␣
lepa␣c
hacacr
e␣trws
toiht␣
echrh␣
rtaaec
str,r␣
noassp
tnii␣o
iecprh
␣eskpe
a␣␣lol
␣eft␣h
rioing
lha␣ac
aercrt
␣tsian
tTc.h␣
␣pechi
rxette
ic␣sr␣
adet␣e
yeb␣ar
rgrain
ghn␣et
pi␣lna
e␣txlt
tretse
ao␣crc
i␣dntg
␣poar␣
deeert
idmn␣e
u␣rloe
␣yrk.e
FG␣L{A
aacers
wl_odu
he_a_v
idlk_e
hete_s
omclnu
}XsXXX
Notice the line
The final key is
Let's modify our Python script to reorder the columns:
def read_file(file_path: str) -> str:
with open(file_path, 'rb') as f:
# read special characters
text = f.read().decode('utf-8')
return text
def detranspose(text: str, columns: int) -> str:
result = ''
rows = [''] * (len(text)//columns)
for i in range (len(text)//columns):
for j in range (columns):
rows[i] += text[i + j * (len(text)//columns)]
for row in rows:
# change order 2, 0, 3, 5, 1, 4
result += row[2]
result += row[0]
result += row[3]
result += row[5]
result += row[1]
result += row[4]
return result
file_path = input("Enter file path: ")
print(detranspose(read_file(file_path), 6).replace('␣', ' '))
After running the script we get the message with flag: