Last active
February 14, 2017 15:47
-
-
Save myles/dc8e214171ba7df772bfab884e6a9220 to your computer and use it in GitHub Desktop.
happy_valentines_day.py
This file contains 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 | |
import argparse | |
def encode(secret): | |
binary = bin(int.from_bytes(secret.encode(), 'big')) | |
return binary[2:].replace('0', 'β€οΈ').replace('1', 'π') | |
def decode(code): | |
binary = int('0b{}'.format(code.replace('β€οΈ', '0').replace('π', '1')), 2) | |
return binary.to_bytes((binary.bit_length() + 7) // 8, 'big').decode() | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument("string", type=str) | |
parser.add_argument('-e', '--encode', action="store_true", | |
help='encode a secret') | |
parser.add_argument('-d', '--decode', action="store_true", | |
help='decode a secret') | |
args = parser.parse_args() | |
if args.encode: | |
print(encode(args.string)) | |
elif args.decode: | |
print(decode(args.string)) | |
else: | |
raise NotImplementedError |
This file contains 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
Python 3.6.0 (default, Dec 24 2016, 08:01:42) | |
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import happy_valentines_day | |
>>> happy_valentine_day.encode("Happy Valentine's Day!") | |
'πβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈππβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈπππβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈπππβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈππππβ€οΈβ€οΈπβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈπβ€οΈππβ€οΈβ€οΈππβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈππβ€οΈππβ€οΈβ€οΈβ€οΈππβ€οΈβ€οΈπβ€οΈπβ€οΈππβ€οΈπππβ€οΈβ€οΈπππβ€οΈπβ€οΈβ€οΈβ€οΈππβ€οΈπβ€οΈβ€οΈπβ€οΈππβ€οΈπππβ€οΈβ€οΈππβ€οΈβ€οΈπβ€οΈπβ€οΈβ€οΈπβ€οΈβ€οΈπππβ€οΈπππβ€οΈβ€οΈππβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈππβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈππππβ€οΈβ€οΈπβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈπ' | |
>>> happy_valentine_day.decode('πβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈππβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈπππβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈπππβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈππππβ€οΈβ€οΈπβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈπβ€οΈππβ€οΈβ€οΈππβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈππβ€οΈππβ€οΈβ€οΈβ€οΈππβ€οΈβ€οΈπβ€οΈπβ€οΈππβ€οΈπππβ€οΈβ€οΈπππβ€οΈπβ€οΈβ€οΈβ€οΈππβ€οΈπβ€οΈβ€οΈπβ€οΈππβ€οΈπππβ€οΈβ€οΈππβ€οΈβ€οΈπβ€οΈπβ€οΈβ€οΈπβ€οΈβ€οΈπππβ€οΈπππβ€οΈβ€οΈππβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈππβ€οΈβ€οΈβ€οΈβ€οΈπβ€οΈππππβ€οΈβ€οΈπβ€οΈβ€οΈπβ€οΈβ€οΈβ€οΈβ€οΈπ') | |
"Happy Valentine's Day!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment