Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Try to match all the words in encrypt text
- """
- import re
- ENCRYPT_TEXT = "Sm ppl cmprs txt msgs by rtnng only ths vwls tht bgn "
- ENCRYPT_TEXT += "a wrd and by rplcng dbld ltrs wth sngl ltrs"
- ENCRYPT_TEXT = ENCRYPT_TEXT.split()
- def main():
- """
- The main function
- """
- word_dict = {}
- answer = {}
- # Build the dictionary by first letter
- for capital in range(ord('a'), ord('z')+1):
- word_dict[chr(capital)] = []
- with open("/usr/share/dict/words", "r") as dict_file:
- for word in dict_file.readlines():
- word = word.strip()
- if len(word) > 0:
- word_dict[word[0].lower()].append(word)
- for capital in word_dict.keys():
- word_dict[capital] = "\n".join(word_dict[capital])
- # For each word, try to find it in dictionary
- for word in ENCRYPT_TEXT:
- reg_re = word[0] + "".join([".*"+c for c in word[1:]]) + ".*"
- reg_re = reg_re.lower()
- answer[word] = re.findall(reg_re, word_dict[reg_re[0]])
- print answer
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement