mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-08 03:00:37 +00:00
Auto urgent commit.
This commit is contained in:
30
cesar/chiffrement.py
Normal file
30
cesar/chiffrement.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import string
|
||||
|
||||
def load_file():
|
||||
with open("message.txt", "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
return content
|
||||
|
||||
lower_case = string.ascii_lowercase
|
||||
upper_case = string.ascii_uppercase
|
||||
|
||||
def dechiffrer(content, step):
|
||||
resultat = ""
|
||||
|
||||
for char in content:
|
||||
if char in lower_case:
|
||||
index = (lower_case.index(char) - step) % 26
|
||||
resultat += lower_case[index]
|
||||
elif char in upper_case:
|
||||
index = (upper_case.index(char) - step) % 26
|
||||
resultat += upper_case[index]
|
||||
else:
|
||||
resultat += char
|
||||
|
||||
return resultat
|
||||
|
||||
contenu = load_file()
|
||||
texte_dechiffre = dechiffrer(contenu, step=17)
|
||||
|
||||
print("Texte déchiffré :")
|
||||
print(texte_dechiffre)
|
||||
Reference in New Issue
Block a user