Skip to content

Instantly share code, notes, and snippets.

@Netmisa
Created December 28, 2025 15:24
Show Gist options
  • Select an option

  • Save Netmisa/fed5c82d1c8deecaa0925b45376be8b2 to your computer and use it in GitHub Desktop.

Select an option

Save Netmisa/fed5c82d1c8deecaa0925b45376be8b2 to your computer and use it in GitHub Desktop.
## Description
Connectez-vous au service distant et pour chaque chaîne de caractères reçue, vous devez renvoyer la chaîne de caractères contenant les caractères dans l’ordre inverse.
__Exemple__ : pour la chaîne ANSSI, vous devez renvoyer ISSNA (note : le respect de la casse est important).
## Solution
```python
import socket
import re
HOST = "localhost"
PORT = 4000
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((HOST, PORT))
while True:
response = socket.recv(1024).decode("utf-8")
if not response:
break
text_found = re.findall(r">>> (\w+)", response)
if len(text_found):
socket.send(f"{text_found[0][::-1]}\n".encode("utf-8"))
print(response)
socket.close()
```
## Explication
Le script va se connecter au service distant pour recevoir les chaînes de caractères à inverser.
J'utilise re.findall pour extraire la chaîne de caractères à inverser.
Ensuite, j'inverse la chaîne avec la syntaxe `chaine[::-1]` et j'envoie la réponse au service distant.
Je continue ainsi jusqu'à ce que le service arrête la connexion. (Ou on peut ajouter une condition d'arrêt si on détecte le flag dans la réponse).
## Résultat
```bash
$ python main.py
>>> ANSSI
Well done, continue!
>>> Agence
Well done, continue!
>>> nationale
Well done, continue!
>>> Oui
Well done, continue!
>>> Bonjour
Well done, continue!
>>> France
Well done, continue!
>>> baguette
Well done, continue!
>>> cassoulet
Well done, continue!
>>> cZCSVNXC
Well done, continue!
>>> v912x8cA
Well done, continue!
>>> 0d93NfdX
Well done, continue!
>>> 5kmQ7KmR
Well done, continue!
>>> jBxqw5cb
Well done, continue!
>>> uKJSGbLz
Well done, continue!
>>> YugsxXm0
Well done, continue!
>>> ul5H4LGG
Well done, continue!
>>> znuxrhp4Ehseyr3F6fwewgTr6nvPDAgi
Well done, continue!
>>> 1SqT3w777yf7mf9Ss9SDDpD471HvV5i5
Well done, continue!
>>> Zlbsf8IJin6Y8qGv5CNxHAk1V1ocvTvu
Well done, continue!
>>> 77XJ4qZg4u3JL1j7WVdndNte6BFOapG7
Well done, continue!
>>> kZApxYt20WKh6OeN9F1oOF7auSLY42ZU
Well done, continue!
>>> vjR2pNyuFbNlwZaJL9Dmv8mEsxjtvth5
Well done, continue!
>>> jxd4tlOlUS5AiuFFkaM2Z6sOgw8KXN9b
Well done, continue!
>>> mx7dEjAMQ17VZ6WNFoJ5JjMmWLF7vYiU
Well done, continue!
Congratulations!! Here is your flag:
FCSC{7b20416c4f019ea4486e1e5c13d2d1667eebac732268b46268a9b64035ab294d}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment