Converting a string to a number by using INT (no hash method)
Dave Angel
d at davea.name
Tue Jan 22 14:08:14 EST 2013
On 01/22/2013 01:37 PM, Ferrous Cranus wrote:
>
>> <snip>
>>
>
> ==============================================
> pin = int( htmlpage.encode("hex"), 16 ) % 10000
> ==============================================
>
> Can you please explain the differences to what you have posted opposed to this perl coding?
>
> ==============================================
> foreach my $ltr(@ltrs){
> $hash = ( $hash + ord($ltr)) %10000;
> ==============================================
>
> I want to understand this and see it implemented in Python.
>
The perl code will produce the same hash for "abc.html" as for
"bca.html" That's probably one reason Leonard didn't try to
transliterate the buggy code.
In any case, the likelihood of a hash collision for any non-trivial
website is substantial. As I said elsewhere, if you hash 100 files you
have about a 40% chance of a collision.
If you hash 220 files, the likelihood is about 90%
--
DaveA
More information about the Python-list
mailing list