Created
June 22, 2015 23:40
-
-
Save khult/648a07758135372c9226 to your computer and use it in GitHub Desktop.
Simple Vigner Cipher in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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