Attachment 'crypto_epure.py'

Download

   1 #!/usr/bin/python3
   2 
   3 def cesar1(car,k):
   4 	a_   = ord('a')
   5 	z_   = ord('z')
   6 	car_ = ord(car)
   7 	if a_ <= car_ <= z_:
   8 		longueur = z_ - a_ + 1
   9 		decalage = (car_ - a_ + k) % longueur
  10 		return chr(a_+decalage)
  11 	else:
  12 		return car
  13 
  14 def cesar(message, k):
  15 	k = int(k)
  16 	code = ""
  17 	for car in message:
  18 		code = code + cesar1(car,k)
  19 	return code
  20 
  21 def de_cesar(message, k):
  22 	return cesar(message, -k)
  23 
  24 def vigenere(message, cle):
  25 	code = ""
  26 	i = 0
  27 	for car in message:
  28 		k = ord(cle[i])-ord('a')
  29 		code = code + cesar1(car,k)
  30 		i = (i+1) % len(cle)
  31 	return code
  32 
  33 def de_vigenere(message, cle):
  34 	code = ""
  35 	i = 0
  36 	for car in message:
  37 		k = ord(cle[i])-ord('a')
  38 		code = code + cesar1(car,-k)
  39 		i = (i+1) % len(cle)
  40 	return code

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2012-12-06 10:14:06, 4.7 KB) [[attachment:crypto.py]]
  • [get | view] (2012-12-06 10:30:05, 0.7 KB) [[attachment:crypto_epure.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.