Makeshift
Catégorie: Crypto Difficulté: very-easy Flag: HTB{4_b3tTeR_w3apOn_i5_n3edeD!?!}
Challenge
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.
Analyse du code
Voici le code commenté pour le comprendre :
from secret import FLAG
# On commence par inverser l'ordre des lettres (ex: ABCD -> DCBA)
flag = FLAG[::-1]
new_flag = ''
# On fait des groupes de 3 lettres
for i in range(0, len(flag), 3):
new_flag += flag[i+1] # On récupère d'abord la 2nd lettre
new_flag += flag[i+2] # Puis la 3e
new_flag += flag[i] # Et enfin la première
# (ex: ABCDEF -> ABC DEF -> BCA EFD -> BCAEFD)
print(new_flag)
Pour déchiffrer il suffit donc d’inverser les étapes, d’abord remettre par groupe de 3 lettres le bon ordre, puis lire la phrase à l’envers
Script de résolution
def solve():
encrypted = "!?}De!e3d_5n_nipaOw_3eTR3bt4{_THB"
flag = ''
for i in range(0, len(encrypted), 3):
flag += encrypted[i + 2]
flag += encrypted[i + 0]
flag += encrypted[i + 1]
flag = flag[::-1]
print(f"Flag: {flag}")
if __name__ == '__main__':
solve()
Dernière mise à jour
Cet article vous a-t-il été utile ?