Skip to content

Instantly share code, notes, and snippets.

@CatTrinket
Last active January 10, 2018 18:38
Show Gist options
  • Save CatTrinket/e5f54f77963d48a688210509fab64c73 to your computer and use it in GitHub Desktop.
Save CatTrinket/e5f54f77963d48a688210509fab64c73 to your computer and use it in GitHub Desktop.
Backwards when rot13'd:
an <-> na
fans <-> snaf
fobs <-> sbof
gnat <-> tang
ravine <-> enivar
re <-> er
robe <-> ebor
serf <-> fres
tang <-> gnat
thug <-> guht
uh <-> hu
Other word when rot13'd:
ah <-> nu
aha <-> nun
ant <-> nag
balk <-> onyx
bar <-> one
barf <-> ones
be <-> or
bin <-> ova
crag <-> pent
ebbs <-> roof
envy <-> rail
errs <-> reef
flap <-> sync
fur <-> she
gel <-> try
gnat <-> tang
if <-> vs
irk <-> vex
from string import ascii_lowercase as alphabet
def get_words(words=[]):
if not words:
with open('/usr/share/dict/words') as word_file:
for word in word_file:
word = word.strip()
if len(word) > 1 and all(c in alphabet for c in word):
words.append(word)
return words
def rot13_table():
return str.maketrans(alphabet, alphabet[13:] + alphabet[:13])
def rot13(word, table=rot13_table()):
return word.translate(table)
def backwards_rot13s():
back_words = []
for word in get_words():
backwards = word[::-1]
if backwards == rot13(word):
back_words.append((word, backwards))
return back_words
def other_word_rot13s():
words = get_words()
set_words = set(words)
other_words = []
for word in words:
if word.startswith('n'):
break
other_word = rot13(word)
if other_word in set_words:
other_words.append((word, other_word))
return other_words
def main():
print("Backwards when rot13'd:")
for (word, backwards) in backwards_rot13s():
print('{} <-> {}'.format(word, backwards))
print()
print("Other word when rot13'd:")
for (word, other) in other_word_rot13s():
print('{} <-> {}'.format(word, other))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment