publicMasters/python/5/codage.py
pvalarcher b92cb19bfc csv
2022-11-18 09:17:43 +01:00

54 lines
668 B
Python
Executable File

#!/usr/bin/env python3
import random
file_message = open("message.txt", "r")
file_cle = open("cle.txt", "w")
file_code = open("code.txt", "w")
## Supposons que message.txt contienne
## Il
## fait
## beau!
lignes = file_message.readlines()
for message in lignes:
longM = len(message)
cle = ""
for i in range(longM):
j = random.randint(0,127)
l = chr(j)
cle = cle + l
file_cle.write(cle)
messagecode = ""
for i in range (longM):
ccode = chr( (ord(message[i]) + ord(cle[i])) % 127)
messagecode = messagecode + ccode
file_code.write(messagecode)
file_message.close()
file_cle.close()
file_code.close()