A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://gist.github.com/0a91e52efa74f61858b5 below:

Proposed Python hashdos fix · GitHub

Created December 31, 2011 00:27

Clone this repository at <script src="https://gist.github.com/PaulMcMillan/0a91e52efa74f61858b5.js"></script>

Save PaulMcMillan/0a91e52efa74f61858b5 to your computer and use it in GitHub Desktop.

Proposed Python hashdos fix

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 #copied from pypy to make it convenient to run the code def intmask(n): if isinstance(n, int): return int(n) # possibly bool->int assert not isinstance(n, float) n = long(n) n &= 18446744073709551615 if n >= 9223372036854775808: n -= 2*9223372036854775808 return int(n) #Original PyPY version #-------------------------------------- def _hash_string(s): """The algorithm behind compute_hash() for a string or a unicode.""" length = len(s) if length == 0: return -1 x = ord(s[0]) << 7 i = 0 while i < length: x = intmask((1000003*x) ^ ord(s[i])) i += 1 x ^= length return intmask(x) #Proposed replacement #-------------------------------------- import os, array size_exponent = 14 #adjust as a memory/security tradeoff r = array.array('l', os.urandom(2**size_exponent)) len_r = len(r) def _hash_string2(s): """The algorithm behind compute_hash() for a string or a unicode.""" length = len(s) #print s if length == 0: return -1 x = (ord(s[0]) << 7) ^ r[length % len_r] i = 0 while i < length: x = intmask((1000003*x) ^ ord(s[i])) x ^= r[x % len_r] i += 1 x ^= length return intmask(x)

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4