Skip to content

Instantly share code, notes, and snippets.

@khult
Created June 22, 2015 23:40
Show Gist options
  • Save khult/648a07758135372c9226 to your computer and use it in GitHub Desktop.
Save khult/648a07758135372c9226 to your computer and use it in GitHub Desktop.
Simple Vigner Cipher in Python
##Kristofer Hult, Computer Security HW1
from string import punctuation
Begin = 97
Finish = 122
def askKey():
key = input("What would you like to set for your key?: ")
return key.lower()
def getPlaintext():
plaintext = input("Please enter text to be encrypted: ")
return plaintext
def runEncrypt(key, plaintext):
ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
cryptText = ''
noWhiteSpace = ''
## for z in range(0, len(plaintext), 1):
## noPunct=''
## noPunct += plaintext[z].strip(punctuation)
## noWhiteSpace = ''
for z in range(0, len(plaintext), 1):
noWhiteSpace += plaintext[z].replace(" ","")
plantext=noWhiteSpace
for n in range(0, len(plaintext), 1):
if plaintext[n].islower():
bottomNew = ord(plaintext[n]) + ord(key[n%len(key)]) - Begin
if (bottomNew > Finish) or (bottomNew < Begin):
bottomNew-=len(ABC)
cryptText += chr(bottomNew)
else:
nextNew = plaintext[n]
cryptText += nextNew
return cryptText
def printCryptText(cryptText):
print ('Your Encryption is ', cryptText)
def main():
key = askKey()
plaintext=getPlaintext()
cryptText=runEncrypt(key, plaintext)
printCryptText(cryptText)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment