diff --git a/_posts/2018-07-01-ndh16.md b/_posts/2018-07-01-ndh16.md index e9bd61f..d52f0bd 100644 --- a/_posts/2018-07-01-ndh16.md +++ b/_posts/2018-07-01-ndh16.md @@ -38,7 +38,7 @@ On avait donc : decode = (encode + 75) % 128 ``` -Et voici un script python simple pour réaliser toutes les étapes : +Et voici un script python 3 simple pour réaliser toutes les étapes : ```python with open('communication_vBZvcbm.txt', 'rb') as f: @@ -52,6 +52,8 @@ with open('communication_vBZvcbm.txt', 'rb') as f: input() ``` +*NB: si vous obtenez un `TypeError: cannot concatenate 'str' and 'int' objects` c'est que vous venez d'exécuter le script avec python 2 au lieu de python 3 ! Il est temps de se mettre à jour ! Si vous insistez, j'ai aussi codé [une version en python 2](/assets/code/cesar-python2.py)* + Le message une fois déchiffré était le suivant : > Bonjour, diff --git a/assets/code/cesar-python2.py b/assets/code/cesar-python2.py new file mode 100644 index 0000000..fabbef0 --- /dev/null +++ b/assets/code/cesar-python2.py @@ -0,0 +1,10 @@ +with open('communication_vBZvcbm.txt', 'rb') as f: + all_bytes = f.readlines() + all_bytes = all_bytes[0] + all_bytes[1] + for n in range(1,128): + dec = [0] * len(all_bytes) + for i in range(len(all_bytes)): + dec[i] = (ord(all_bytes[i]) + n) % 128 + print(''.join([chr(x) for x in dec])) + raw_input() +