Last active
July 15, 2022 08:48
-
-
Save bennuttall/c149f85251449053c7bfb1a4d08b37a7 to your computer and use it in GitHub Desktop.
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
from string import ascii_lowercase | |
import argparse | |
import random | |
LINUX_SYSTEM_DICT = '/usr/share/dict/american-english' | |
MAC_SYSTEM_DICT = '/usr/share/dict/words' | |
BIG_WORDLIST = 'words.txt' | |
# wordlist = LINUX_SYSTEM_DICT | |
wordlist = MAC_SYSTEM_DICT | |
# wordlist = BIG_WORDLIST | |
with open(wordlist) as f: | |
WORDS = { | |
word.lower().strip() | |
for word in f | |
if all(c.lower() in ascii_lowercase for c in word.strip()) | |
} | |
def encode(word: str) -> str: | |
n = len(word) - 2 | |
return f"{word[0]}{n}{word[-1]}" | |
def decode(numeronym: str) -> str: | |
a, *b, c = numeronym | |
b = int(''.join(b)) | |
return { | |
word | |
for word in WORDS | |
if len(word) == b + 2 | |
and word[0] == a | |
and word[-1] == c | |
} | |
def main(args): | |
if args.encode is not None: | |
print(encode(args.encode)) | |
if args.decode is not None: | |
words = decode(args.decode) | |
if len(words) == 0: | |
print("No words found") | |
if args.lucky: | |
print(random.choice(list(words))) | |
else: | |
for word in words: | |
print(word) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-e', '--encode', type=str) | |
parser.add_argument('-d', '--decode', type=str) | |
parser.add_argument('-l', '--lucky', action='store_true') | |
args = parser.parse_args() | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you read about k8s, a11y, i18n, l10n, m17n, c14n and v12n - but no idea what people are talking about? It's not because you're stupid - it's because they're obtusely using numeronyms! Numeronyms are a cryptographically (c15y) secure way to compress long words using a one-way hash, meaning they cannot usually be decrypted.
Want to try to decrypt a numeronym you just read about? Good luck:
Are you feeling lucky?
Yeah I think that's what that tweet was about.
You can even use this program to make your own numeronym!
Want to turn a long word into a numeronym?
Want to turn a short word into a numeronym?
Want to turn a shorter word into a numeronym?
Want to turn an even shorter word into a numeronym?
Want to turn an even shorter word into a numeronym?
Ok I'll stop now.