Saturday, 29 August 2015

Vigenere Cipher

A vigenere Cipher uses a different strategy to create the key stream. The key stream is repetition of initial key stream of length m  where we have  1<=key<=26 .


GET More Basic Crypto AlgorithmsGithub

Python Source Code :

  1. # Vigenere Cipher
  2. # codecops.in
  3. def VigenereCipher(plainText,keys):
  4.     # Vigenere Cipher
  5.     plainText=plainText.upper()
    plainText=plainText.replace(' ','')
  6.     block=len(keys)
  7.     sizep=len(plainText)
  8.     cipher=[]
  9.     for i in range(0,sizep,block):
  10.         if i+block<=sizep:
  11.             for j in range(i,i+block):
  12.                 cipher.append(chr((((ord(plainText[j])-64)+keys[j-i])%26 +64)))
  13.         else:
  14.             for j in range(i,sizep):
  15.                 cipher.append(chr((((ord(plainText[j])-64)+keys[j-i])%26 +64)))
  16.     return "".join(cipher)
  17. if __name__=='__main__':
  18.     pt=raw_input("Plain Text : ")
  19.     key=[int(x) for x in raw_input("key Stream : ").split(' ')]
  20.     print "Vigenere Cipher"
  21.     print VigenereCipher(pt,key)

Output :
Vigenere cipher Output

1 comment:

THANKS FOR UR GREAT COMMENT

Blogger Widgets