Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. class infinitelist(object):
  2. #allows a list to be accessed infinitely, where indexes beyond it's length are reduced to match an index.
  3. def __init__(self, lst):
  4. self.lst = lst
  5. def __repr__(self):
  6. return str(self.lst)
  7. def __len__(self):
  8. return len(self.lst)
  9. def __getitem__(self, i):
  10. if i == len(self.lst):
  11. return self.lst[i%len(self.lst)]
  12. elif i > len(self.lst)-1:
  13. return self.lst[i%len(self.lst)-1]
  14. else:
  15. return self.lst[i]
  16.  
  17.  
  18. def num_hash(i):
  19. chars = ['a', 'b', 'c', 'd',
  20. 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  21. 'n', 'o', 'p', 'q', 'r', 's',
  22. 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
  23. '3', '4', '5', '6', '7', '8', '9']
  24. selection = infinitelist([x+y for x in chars for y in chars])
  25. hashed = ''
  26. while len(hashed) < 16:
  27. if i % 2 == 0:
  28. hashed += selection[i]
  29. i *= 4
  30. elif len(hashed) % 2 == 0:
  31. hashed += selection[i+4]
  32. i *= 3
  33. else:
  34. hashed += selection[i+1]
  35. i += 8
  36. return hashed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement