Created
June 30, 2020 05:47
-
-
Save turnipsoup/db401d4fdc698fd2081e3e84f9eaaca3 to your computer and use it in GitHub Desktop.
Get T9 text words from string of phone-entered digits.
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
#!/usr/bin/env python3 | |
str_one = "444333 99966688 277733 7773323444664 84433 22244474433777, 99966688 277733 666552999. 99966688777 777744277733 666333 84433 443344477778 4447777 44466 99966688777 4466688777733. 84433 5533999 8666 84433 55566622255 4447777 22335556669. 4666 8666 727774447777." | |
str_two = "47777888 995559888 4555 47777888 44999988 666555997 : 8555444888477744488866888648833369!!" | |
t9_text = { | |
"2": "a", | |
"22": "b", | |
"222": "c", | |
"3": "d", | |
"33": "e", | |
"333": "f", | |
"4": "g", | |
"44": "h", | |
"444": "i", | |
"5": "j", | |
"55": "k", | |
"555": "l", | |
"6": "m", | |
"66": "n", | |
"666": "o", | |
"7": "p", | |
"77": "q", | |
"777": "r", | |
"7777": "s", | |
"8": "t", | |
"88": "u", | |
"888": "v", | |
"9": "w", | |
"99": "x", | |
"999": "y", | |
"9999": "z" | |
} | |
def getsinglenumbergroup(num_message): | |
char_str = num_message[0] | |
for char in num_message[1:]: | |
if char == char_str[-1]: | |
char_str += char | |
else: | |
break | |
return char_str | |
def getnumbergroups(num_message): | |
number_groups = [] | |
while True: | |
try: | |
num_string = getsinglenumbergroup(num_message) | |
number_groups.append(num_string) | |
num_message = num_message[len(num_string):] | |
except: | |
break | |
return number_groups | |
def numberstowords(num_str_list, t9_text): | |
decoded_str = "" | |
for number in num_str_list: | |
decoded_str += t9_text[number] | |
return decoded_str | |
def getsentence(num_sentence): | |
decoded_sentence = "" | |
num_sentence = num_sentence.replace(".", "").replace(",", "").replace(":", "").replace("!","") | |
for word in num_sentence.split(" "): | |
word_groups = getnumbergroups(word) | |
decoded_sentence += numberstowords(word_groups, t9_text) | |
decoded_sentence += " " | |
return decoded_sentence.upper() | |
print(getsentence(str_one)) | |
print() | |
print(print(getsentence(str_two))) | |
# https://cryptii.com/ | |
# Reverse alphabetical substitution | |
# gsv xlwv gl gsv hzu olxp : tlivgrivnvmgufmw !! | |
# THE CODE TO THE SAF LOCK : GORETIREMENTFUND !! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment