Files
picoCTF/spelling_quiz/public/encrypt.py
Maxime Vorwerk e96f171871 spelling-quiz
2024-07-08 16:49:12 +02:00

28 lines
579 B
Python
Executable File

#!/home/maxime/.pyvenv/bin/python3
import random
import os
files = [
os.path.join(path, file)
for path, dirs, files in os.walk('.')
for file in files
if file.split('.')[-1] == 'txt'
]
print(files)
alphabet = list('abcdefghijklmnopqrstuvwxyz')
random.shuffle(shuffled := alphabet[:])
dictionary = dict(zip(alphabet, shuffled))
print(dictionary)
for filename in files:
text = open(filename, 'r').read()
encrypted = ''.join([
dictionary[c]
if c in dictionary else c
for c in text
])
#open(filename, 'w').write(encrypted)