Created
October 16, 2019 07:46
-
-
Save yjkellyjoo/3639458cd836426bb87ca177a0354e8e to your computer and use it in GitHub Desktop.
simple python2 code for decrypting mono alphabetic cipher
This file contains 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
#!/usr/bin/python | |
#Mono Alphabetic Cipher with user defined key | |
from collections import OrderedDict | |
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
KEYPHRASE = '' | |
def makeKeyphrase(key): | |
##remove repeated alphabets | |
KEYPHRASE = "".join(OrderedDict.fromkeys(key)) | |
##make keyphrase | |
lastInd = LETTERS.find(KEYPHRASE[len(KEYPHRASE)-1]) | |
subletter = LETTERS[lastInd:len(LETTERS)] | |
proletter = LETTERS[0:lastInd] | |
KEYPHRASE += ''.join( c for c in subletter if c not in KEYPHRASE) | |
KEYPHRASE += ''.join( c for c in proletter if c not in KEYPHRASE) | |
print('key phrase: ' + KEYPHRASE) | |
print('letters: ' + LETTERS) | |
def decryptMessage(message): | |
translated = '' | |
## something wrong with using symbol in find() method? | |
for symbol in message: | |
symIndex = KEYPHRASE.find(symbol[0]) | |
translated += LETTERS[symIndex] | |
print(translated) | |
def main(): | |
message = raw_input("message to crack: ") | |
key = raw_input("key used to cipher: ") | |
makeKeyphrase(key) | |
#decryptMessage(message) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment