1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import os, sys, array, operator
from itertools import cycle, imap
filename = sys.argv[1]
pw = "MONSUPERMOTDEPASS"
pw = map(ord, pw) # convertit en liste d'entiers une fois pour toutes
arr = array.array('B')
with open(filename, 'rb') as f:
# détermine la taille du fichier
f.seek(0, os.SEEK_END)
sz = f.tell()
f.seek(0, os.SEEK_SET)
# lit le contenu du fichier dans le tableau
arr.fromfile(f,sz)
# calcul du résultat
arr = array.array('B',imap(operator.xor, arr, cycle(pw)))
# écriture du résultat
filename = os.path.splitext(filename)[0] + '.flc'
with open(filename, 'wb') as f:
arr.tofile(f) |
Partager