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

2 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Data Science with Python , kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on TECHNOLOGY. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Sangita Mohanty
    MaxMunus
    E-mail: sangita@maxmunus.com
    Skype id: training_maxmunus
    Ph:(0) 9738075708 / 080 - 41103383
    http://www.maxmunus.com/

    ReplyDelete

THANKS FOR UR GREAT COMMENT

Blogger Widgets