Skip to content

Instantly share code, notes, and snippets.

@sjparkinson
Last active December 21, 2015 08:59
Show Gist options
  • Save sjparkinson/6282139 to your computer and use it in GitHub Desktop.
Save sjparkinson/6282139 to your computer and use it in GitHub Desktop.
class LittleWords:
dictonary = ['a', 'aid', 'ana', 'arc', 'at', 'awn', 'bar', 'bet', 'bog', 'bug', 'cab', 'cod', 'coy', 'dad', 'des', 'doe', 'due', 'ego', 'etc', 'fat', 'fir', 'fum', 'gap', 'gil', 'guy', 'hap', 'her', 'hit', 'how', 'icy', 'ion', 'ivy', 'jet', 'joy', 'kim', 'lam', 'len', 'lit', 'low', 'man', 'mel', 'mod', 'mug', 'nay', 'nip', 'nov', 'oar', 'oil', 'orr', 'owl', 'pap', 'pep', 'pit', 'pro', 'rag', 'red', 'rip', 'rub', 'sag', 'sea', 'sin', 'so', 'spy', 'tad', 'ten', 'to', 'toy', 'up', 'wag', 'wet', 'wow', 'yes', 'ache', 'aden', 'aids', 'ally', 'ames', 'anna', 'argo', 'aunt', 'away', 'bait', 'band', 'barn', 'bawd', 'beau', 'belt', 'beta', 'bill', 'bled', 'blur', 'bohr', 'bone', 'bore', 'boyd', 'brig', 'bull', 'burt', 'cafe', 'cane', 'cash', 'chad', 'chin', 'clad', 'club', 'code', 'colt', 'cord', 'crag', 'cube', 'curl', 'dang', 'date', 'dean', 'defy', 'diet', 'dish', 'dome', 'dour', 'drub', 'duke', 'each', 'eddy', 'elba', 'eros', 'fail', 'fast', 'fell', 'file', 'fish', 'flat', 'flow', 'folk', 'fork', 'fray', 'full', 'gage', 'game', 'gave', 'gibe', 'gist', 'glow', 'goes', 'gory', 'grew', 'gulf', 'haag', 'halo', 'harm', 'hawk', 'heed', 'here', 'hike', 'hobo', 'hone', 'host', 'huff', 'hurd', 'idea', 'iowa', 'jack', 'jerk', 'jobs', 'jove', 'june', 'kane', 'kern', 'kiss', 'know', 'lack', 'lame', 'late', 'leak', 'lent', 'lick', 'lila', 'link', 'loam', 'long', 'lost', 'lulu', 'lyle', 'mail', 'mann', 'mash', 'mead', 'memo', 'mild', 'mini', 'moan', 'mona', 'morn', 'mudd', 'mutt', 'nash', 'neil', 'nibs', 'noel', 'noun', 'odin', 'olin', 'onus', 'outs', 'quod', 'rain', 'rays', 'reek', 'rice', 'rink', 'rock', 'room', 'rove', 'rule', 'rust', 'salk', 'saul', 'seam', 'self', 'shaw', 'show', 'silk', 'site', 'skit', 'slim', 'slur', 'soak', 'some', 'sown', 'stir', 'sums', 'swan', 'take', 'teal', 'tend', 'thee', 'tick', 'time', 'toil', 'toot', 'tram', 'trot', 'tune', 'ulan', 'vain', 'vein', 'vine', 'wail', 'wane', 'wast', 'wean', 'went', 'whet', 'wine', 'wolf', 'worn', 'yarn']
def ip2w(self, ip):
if type(ip) != type(str()):
raise TypeError("The IP must be of type string.")
else:
words = list()
fragment = ip.split(".")
i = 0
while i < 4:
words.append(self.dictonary[int(fragment[i])])
i = i + 1
return words
def w2ip(self, words):
if type(words) != type(str()):
raise TypeError("The words must be of type string.")
else:
split = list()
ip = str()
words = words.lower().split(" ")
if len(words) != 4:
raise ValueError("The string must contain 4 words.")
else:
i = 0
while i < 4:
split.append(str(self.dictonary.index(words[i])))
i = i + 1
ip = ".".join(split)
return ip
lw = LittleWords()
print lw.ip2w("127.0.0.1")
print lw.w2ip("fell a a aid")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment