#VET - Vigenere Encipherment Tool import os, sys def getText(string): text = raw_input(string) while len(text) == 0: text = raw_input(string) return text def cipher(pchar, kchar): pascii = ord(pchar) kascii = ord(kchar) if kchar.isalpha(): if kascii > 96: kascii = kascii - 97 else: kascii = kascii - 65 else: print 'invalid key sequence' raise SystemExit if pchar.isalpha(): if pascii > 96: pascii = pascii + kascii if pascii > 122: pascii = pascii - 26 return chr(pascii) else: return chr(pascii) else: pascii = pascii + kascii if pascii > 90: pascii = pascii - 26 return chr(pascii) else: return chr(pascii) else: return pchar def cipherLoop(plaintext, key): keycounter = 0 charcounter = 0 keytext = key.replace(' ','') ciphertext = '' while charcounter < len(plaintext): keychar = keytext[keycounter] plainchar = plaintext[charcounter] charcounter = charcounter + 1 if plainchar != ' ': ciphertext = ciphertext + cipher(plainchar, keychar) keycounter = keycounter + 1 if keycounter == len(keytext): keycounter = 0 else: ciphertext = ciphertext + ' ' return ciphertext print cipherLoop(getText('Please enter plaintext>'), getText('Please enter key>'))