Skip to content

Instantly share code, notes, and snippets.

@steverichey
Last active August 19, 2020 23:41
Show Gist options
  • Save steverichey/8f38ba90f8075e65122940c99bfdcbb6 to your computer and use it in GitHub Desktop.
Save steverichey/8f38ba90f8075e65122940c99bfdcbb6 to your computer and use it in GitHub Desktop.
import sys
pair_table = {
"a" : ("", 1),
"b" : ("", 2),
"c" : ("", 3),
"d" : ("", 4),
"e" : ("", 5),
"f" : ("", 6),
"g" : ("", 7),
"h" : ("", 8),
"i" : ("", 9),
"j" : ("", 10),
"k" : ("b", 1),
"l" : ("b", 2),
"m" : ("b", 3),
"n" : ("b", 4),
"o" : ("b", 5),
"p" : ("b", 6),
"q" : ("b", 7),
"r" : ("b", 8),
"s" : ("b", 9),
"t" : ("b", 10),
"u" : ("c", 1),
"v" : ("c", 2),
"w" : ("c", 3),
"x" : ("c", 4),
"y" : ("c", 5),
"z" : ("c", 6),
}
def is_not_allowed(char):
return char in [" ", ",", ".", ";", "-"]
def encode_message(str):
encoded = ""
for char in str:
if is_not_allowed(char):
encoded += " "
continue
pair = pair_table[char]
emoji = pair_to_emoji(pair)
encoded += emoji
return encoded
def pair_to_emoji(pair):
letter = pair[0]
number = str(pair[1])
return ":encoded" + letter + number + ": "
message = sys.argv[1:][0].lower()
encoded = encode_message(message)
print(encoded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment