4 ms·
Would someone be so kind as to explain the following: sub morph { my ($number) = @_; return ((((($number % 7) * 13) % 17) * 19) % 23); } It ap
by dmazin 13y ago
Would someone be so kind as to explain the following:
sub morph {
my ($number) = @_;
return ((((($number % 7) * 13) % 17) * 19) % 23);
}
It appears to be some sort of quick authorization check (there is a later `$code == &morph($user)` comparison).
- harpastum 13y agoMaybe some sort of strange hash function? It looks like it spreads the values fairly evenly from 0-23, while keeping nearby numbers separate. Here's what it looks like from 0-5: http://www.wolframalpha.com/input/?i=plot+%28%28%28%28x+mod+7%29+×+13%29+mod+17%29+×+19%29+mod+23+from+0+to+5 http://www.wolframalpha.com/input/?i=plot+%28%28%28%28x+mod+... If the input is only integers, the same pattern still appears: http://www.wolframalpha.com/input/?i=plot+%28%28%28%28floor%28x%29+mod+7%29+×+13%29+mod+17%29+×+19%29+mod+23+from+0+to+20 http://www.wolframalpha.com/input/?i=plot+%28%28%28%28floor%...
- alexeiz 13y agoIt's a really poor hash function. The only possible values are: 0,3,6,10,13,17,19. You can quickly see that only 7 distinct values are possible because of the initial $number % 7.
- curveship 13y ago11, the forgotten prime.