Hex Word Finder – hexwords.py
- May 6th, 2010
- Posted in Programming
- Write comment
UPDATE: I have updated the script to include other letters that can be represented as numbers. An issue lies within words that have both I’s and L’s, because they both get replaced by 1′s, and it can make the word very confusing and kind of useless.
So in an attempt to brush up on my Python a bit, and also just have some fun, I wrote up a little script today that searches a dictionary file for words that can be represented in hexadecimal.
Result from a dictionary of English words I found online:
hexwords.txt
Code:
import sys
def main(*args):
wordfile = args[1]
hexlist = "ABCDEFOILST"
words = open(wordfile,'r')
for word in words:
word = word.upper()
word = word.join(word.split()) # attempt to remove spaces
match = ""
for letter in word:
for hx in hexlist:
if hx == letter:
if hx == 'O':
match += "0"
elif hx == "I":
match += "1"
elif hx == "L":
match += "1"
elif hx == "S":
match += "5"
elif hx == "T":
match += "7"
else:
match += hx
if len(word) == len(match):
print match
words.close()
return True
if __name__ == '__main__':
sys.exit(main(*sys.argv))
No comments yet.