Dec 04, 2024

Wiki

Python

Aide

edit SideBar

Search

Cesar

  #-*-coding:utf8-*-
  def cesar(texte, cle):
      return ''.join([chr((ord(k)-ord('a')+cle)%26+ord('a')) for k in texte])

  def cesar2(texte, cle):
      crypto = ""
      for k in texte.lower():
          # If it is a letter
          if k.isalpha():
              crypto += chr((ord(k)-ord('a')+cle)%26+ord('a'))
          else:
              crypto += k
      return crypto


  texte = raw_input("Quel texte chiffrer ? ")
  cle = input("Quelle clé de chiffrement ? ")
  cryptogram = cesar2(texte, cle)
  print "Texte chiffré :", cryptogram
  print "Texte dechiffré :",cesar2(cryptogram, -cle)

Page Actions

Recent Changes

Group & Page

Back Links