Skip to content

Instantly share code, notes, and snippets.

@myles
Last active February 14, 2017 15:47
Show Gist options
  • Save myles/dc8e214171ba7df772bfab884e6a9220 to your computer and use it in GitHub Desktop.
Save myles/dc8e214171ba7df772bfab884e6a9220 to your computer and use it in GitHub Desktop.
happy_valentines_day.py
#!/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
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