Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active July 15, 2022 08:48
Show Gist options
  • Save bennuttall/c149f85251449053c7bfb1a4d08b37a7 to your computer and use it in GitHub Desktop.
Save bennuttall/c149f85251449053c7bfb1a4d08b37a7 to your computer and use it in GitHub Desktop.
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)
@bennuttall
Copy link
Author

bennuttall commented Jul 14, 2022

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:

$ python numeronyms.py -d i18n             
intercrystallization
interdifferentiation
internationalization
institutionalization

Are you feeling lucky?

$ python numeronyms.py -d a11y --lucky
aboriginality

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?

$ python numeronyms.py -e numeronym
n7m

Want to turn a short word into a numeronym?

$ python numeronyms.py -e test
t2t

Want to turn a shorter word into a numeronym?

$ python numeronyms.py -e bin
b1n

Want to turn an even shorter word into a numeronym?

$ python numeronyms.py -e ha
h0a

Want to turn an even shorter word into a numeronym?

$ python numeronyms.py -e x
x-1x

Ok I'll stop now.

@drj11
Copy link

drj11 commented Jul 15, 2022

good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment