hi again i have been looking at the bacon cipher and i have made this
import re
dictionaryofcodes = {'A': '11111', 'B': '11110', 'C': '11101', 'D': '11100', 'E': '110111', 'F': '11010', 'G': '11001', 'H': '11000', 'I': '10111', 'J': '10110', 'K': '10101', 'L': '10100', 'M': '10011', 'N': '10010', 'O': '10001', 'P': '10000', 'Q': '01111', 'R': '01110', 'S': '01101', 'T': '01100', 'U': '01011', 'V': '01010', 'W': '01001', 'X': '01000', 'Y': '00111', 'Z': '00110'}
reversedDictOfCodes = {"11111": "A", '11110': 'B', '11101': 'C', '11100': 'D', '11011': 'E', '11010': 'F', '11001': 'G', '11000': 'H', '10111': 'I', '10110': 'J', '10101': 'K', '10100': 'L', '10011': 'M', '10010': 'N', '10001': 'O', '10000': 'P', '01111': 'Q', '01110': 'R', '01101': 'S', '01100': 'T', '01011': 'U', '01010': 'V', '01001': 'W', '01000': 'X', '00111': 'Y', '00110': 'Z'}
text = 'hello i love this'
def encodeToAB(paragraph):
# Task: encode a paragraph into a string of A and B s.
paragraph = dropAllNonAlphabeticCharacters(paragraph)
paragraph = convertToUpperCase(paragraph)
paragraph = substituteEveryLetterByItsCode(paragraph)
return paragraph
def dropAllNonAlphabeticCharacters(paragraph):
# we can use a regex for this task
pattern = aRegexWhichMatchesGroupsOfNonAlphabeticCharacters()
paragraph = pattern.sub("", paragraph)
return paragraph
def convertToUpperCase(paragraph):
# hey, I know how to do this!
return paragraph.upper()
def substituteEveryLetterByItsCode(paragraph):
L = []
for letter in paragraph:
L.append(getCodeForLetter(letter))
return "".join(L)
def aRegexWhichMatchesGroupsOfNonAlphabeticCharacters():
# to solve this task, I must know the re module
return re.compile(r"[^a-zA-Z]+")
def getCodeForLetter(letter):
return dictionaryofcodes[letter]
p = 'hello'
print(encodeToAB(p))
print(encodeToAB(text))
how can i decode it?
either in a separate program or in the same one?