Skip to content

Instantly share code, notes, and snippets.

@yjkellyjoo
Created October 16, 2019 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjkellyjoo/3639458cd836426bb87ca177a0354e8e to your computer and use it in GitHub Desktop.
Save yjkellyjoo/3639458cd836426bb87ca177a0354e8e to your computer and use it in GitHub Desktop.
simple python2 code for decrypting mono alphabetic cipher
#!/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