Naitsab_33

Vigenère

Jul 10th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import string
  2. import textUtils
  3.  
  4.  
  5. def Enc(text, key):
  6.     alpha = list(string.ascii_uppercase)
  7.     text = textUtils.noUmlauts(text)
  8.     text = text.upper()
  9.     while len(key) < len(text):
  10.         key = key+key
  11.     text = list(text)
  12.     key = key.upper()
  13.     key = list(key)
  14.     dectext = ""
  15.     for i in text:
  16.         if i in alpha:
  17.             index = alpha.index(i)+alpha.index(key[text.index(i)])
  18.             shift = index % 26
  19.             i = alpha[shift]
  20.         dectext = dectext + i
  21.     print(dectext)
  22.  
  23.  
  24. def Dec(text, key):
  25.     alpha = list(string.ascii_uppercase)
  26.     text = textUtils.noUmlauts(text)
  27.     text = text.upper()
  28.     while len(key) < len(text):
  29.         key = key+key
  30.     text = list(text)
  31.     key = key.upper()
  32.     key = list(key)
  33.     dectext = ""
  34.     for i in text:
  35.         if i in alpha:
  36.             index = alpha.index(i)-alpha.index(key[text.index(i)])
  37.             shift = index % 26
  38.             i = alpha[shift]
  39.         dectext = dectext + i
  40.     print(dectext)
  41.  
  42.  
  43. #----------------------------textUtils.py in my Pastebin-------------------------------#
Advertisement
Add Comment
Please, Sign In to add comment