Message lointain
Catégorie: Cryptanalyse - Difficulté: Intro
Description:

Solution:
Ici il s'agit d'un chall très simple où le flag a été chiffré avec la fonction encrypt
:

Le but ici est de créer une fonction decrypt afin de lui donner notre flag et retrouver l'original.
Voici les étapes à suivre :
Pour chaque caractère chiffré, retrouver son indice
y
danscharset
.Retrouver l'entier
x
tel quepow(2, x, n+1) == y
.En déduire le caractère clair d’indice
x
danscharset
.
Avec ces infos, la création de la fonction est très rapide :
inverse_pow2 = {}
for x in range(n):
y = pow(2, x, n+1)
inverse_pow2[y] = x # y est l'indice chiffré, x est l'indice original
def decrypt(ciphertext):
decrypted = []
for char in ciphertext:
if char in charset:
y = charset.index(char)
if y in inverse_pow2:
x = inverse_pow2[y]
decrypted.append(charset[x])
else:
# Cas rare si y ne correspond à aucun pow(2, x, n+1)
decrypted.append('?')
return ''.join(decrypted)
print("DECRYPTED FLAG : ", decrypt("828x6Yvx2sOnzMM4nI2sQ"))
Et voilà le résultat :

Last updated
Was this helpful?