Skip to content

Latest commit

 

History

History
 
 

[Very Easy] Makeshift

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

img

Makeshift

​ 29th Jan 2024 / Document No. D24.102.25

​ Challenge Author(s): ir0nstone

Synopsis

Makeshift is a Very Easy crypto challenge that involves reversing a simple custom "encryption" algorithm.

Description:

Weak and starved, you struggle to plod on. Food is a commodity at this stage, but you can’t lose your alertness - to do so would spell death. You realise that to survive you will need a weapon, both to kill and to hunt, but the field is bare of stones. As you drop your body to the floor, something sharp sticks out of the undergrowth and into your thigh. As you grab a hold and pull it out, you realise it’s a long stick; not the finest of weapons, but once sharpened could be the difference between dying of hunger and dying with honour in combat.

Skills Required

  • Understanding Python code

Skills Learned

  • Undoing programmatic operations

Enumeration

We are given the following script:

from secret import FLAG

flag = FLAG[::-1]
new_flag = ''

for i in range(0, len(flag), 3):
    new_flag += flag[i+1]
    new_flag += flag[i+2]
    new_flag += flag[i]

print(new_flag)

output.txt also gives us an encrypted flag:

!?}De!e3d_5n_nipaOw_3eTR3bt4{_THB

The flag is encrypted in a very simple way:

  • First it is reversed
  • It is then split into groups of three characters, which all have the same thing done to it:
    • The second character is placed first
    • The third character is placed second
    • The first character is placed third
    • In essence, every sequence of characters ABC is changed to BCA

Solution

In order to reverse this, we have to do the same operations in the opposite order. So, given sets of 3 BCA, we have to convert it back to ABC. We can do this by making sure that:

  • The third character is placed first
  • The first character is placed second
  • The second character is placed third

After that, we simple have to reverse it.

enc_flag = r'!?}De!e3d_5n_nipaOw_3eTR3bt4{_THB'

new_flag = ''

for i in range(0, len(enc_flag), 3):
    new_flag += enc_flag[i+2]
    new_flag += enc_flag[i]
    new_flag += enc_flag[i+1]

flag = new_flag[::-1]

print(flag)

And we get the flag!