#! /usr/bin/python3 # -*- coding: utf-8 -*- def carot13(c): """ transforme le caractère c en un caractère rot13 de c i.e. 13 lettres plus loin""" n=ord(c)-97 # transforme la lettre minuscule entre a et z en un entier entre 0 et 25 m=(n+13)%26 # phase de César je tourne la roue (avec des nombres de 0 à 25) d'un demi tour rotc=chr(m+97) # traduction en charactère entre a et z return rotc def marot13(mot): motEnRot="" for c in mot: # print("boucle : " + carot13(c)) # motEnRot = motEnRot + carot13(c) motEnRot += carot13(c) # Même chose que ligne précédente return motEnRot ### En trichant. def rot13(phrase): phraseEnRot="" for c in phrase: if (c != ' '): phraseEnRot += carot13(c) else : phraseEnRot += ' ' return phraseEnRot # test print("test rot13") print("abcdefghijklmnopqrstuvwxyz") print(marot13("abcdefghijklmnopqrstuvwxyz")) print(marot13(marot13("abcdefghijklmnopqrstuvwxyz"))) p="the lazy dog jumped over the quick brown fox" print(rot13(p)) # Sans tricher. #L="the lazy dog jumped over the quick brown fox".split() #L = p.split() #ou comme ceci puisque le message p est défini ci-dessus. #"XX".join(L) #'theXXlazyXXdogXXjumpedXXoverXXtheXXquickXXbrownXXfox' #" ".join(L) #'the lazy dog jumped over the quick brown fox' maListeDeMots=p.split() maListeDeMotsEnRot13=[marot13(mot) for mot in maListeDeMots] #print(maListeDeMotsEnRot13) print(" ".join(maListeDeMotsEnRot13)) ### En une seule fois. MessageSecret="Having a lower tax, simpler, fairer, flatter tax system is something that can drive growth." print(" ".join([marot13(mot) for mot in MessageSecret.split()]))