Created
February 22, 2013 08:08
-
-
Save bmispelon/5011667 to your computer and use it in GitHub Desktop.
Looking for dict collisions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import itertools | |
| from string import ascii_letters | |
| import sys | |
| def collisions(alphabet=ascii_letters, n=6): | |
| d = {} | |
| for i in range(2, n): | |
| for comb in itertools.combinations_with_replacement(alphabet, i): | |
| w = ''.join(comb) | |
| h = hash(w) | |
| if h in d: | |
| return d[h], w | |
| d[h] = w | |
| if __name__ == "__main__": | |
| if len(sys.argv) > 1: | |
| n = int(sys.argv[1]) | |
| else: | |
| n = 6 | |
| collision = collisions(n=n) | |
| if collision: | |
| print 'Collision found: %s, %s' % collision | |
| else: | |
| print 'No collision found :(' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment