Feb-05-2018, 10:44 AM
I just write a python's code for change messages with a chosen letter shift, but it only work for the first letter.
Could you explain me what should i change for making it work with all character
Could you explain me what should i change for making it work with all character
ALPHABET = str()
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def main():
text = input('Entrez le message à chiffrer: ')
offset = int(input('Entrez le décalage à utiliser:'))
message = cesar(text,offset)
print("Le message chiffré est: ", message)
def cesar(text,offset):
text = convert_text(text)
new_text = str()
for char in text:
if char in ALPHABET:
new_text += swap(char,offset)
else:
new_text += char
return new_text
def convert_text(text): #supprime les caractères spéciaux
text = text.lower()
d = {
"e" :["é","è","ê","ê"],
"a" :["à"],
"c" :["ç"],
"o" :["ô"],
"u" :["ù"]
}
for char in d:
for c in d[char]:
text = text.replace (c, char)
return text.upper()
def swap(char, offset):
index = ALPHABET.find(char)
return ALPHABET [(index + offset) % 26]
if "main" == "main":
main()
