publicMasters/python/2/3Rot13.py

24 lines
600 B
Python
Raw Permalink Normal View History

#! /usr/bin/python3
# -*- coding: utf-8 -*-
def carot13(lettre):
"""retourne la lettre correspondante en rot13, on suppose que lettre est entre a et z"""
n=ord(lettre)-97
m=(n+13)%26
rot=chr(m+97)
return rot
def marot13(mot):
"""retourne le mot correspondant en rot13, on suppose que le mot est composé de lettres entre a et z"""
out="";
for lettre in mot:
out+=carot13(lettre)
return out
# test
print("test rot13")
print("abcdefghijklmnopqrstuvwxyz")
print(marot13("abcdefghijklmnopqrstuvwxyz"))
print(marot13(marot13("abcdefghijklmnopqrstuvwxyz")))