Pages

ROT13

Un petit transcripteur ROT13.
Si vous voulez plus d'info sur ROT13, vous pouvez visiter la page de wikipédia.

-----8<----------8<----------8<----------8<----------8<----------8<-----

#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#
# *******
#  ROT13
# *******

import sys

if len(sys.argv)<=1:
    print"""
Usage : ./rot13.py -texte
  -texte  Texte à Transcrire (si plusieurs mots, n'oubliez pas les quotes)
         """
    sys.exit(1)

text=sys.argv[1]
rot13=""

for caract in text:
    if (ord(caract)>=ord('a') and ord(caract)<=ord('z') or
    ord(caract)>=ord('A') and ord(caract)<=ord('Z')):
        if (ord(caract)>=ord('a') and ord(caract)<=ord('m') or
        ord(caract)>=ord('A') and ord(caract)<=ord('M')):
            rot13 += chr(ord(caract)+13)
        if (ord(caract)>=ord('n') and ord(caract)<=ord('z') or
        ord(caract)>=ord('N') and ord(caract)<=ord('Z')):
            rot13 += chr(ord(caract)-13)
    else :
        rot13+= caract

print "[ " + text + " ] = " + rot13
   


-----8<----------8<----------8<----------8<----------8<----------8<-----


On se resservira de ce petit bout de code, pour faire un algorithme sur le chiffre de césar très bientôt.

Aucun commentaire:

Enregistrer un commentaire