#!/usr/bin/perl -w # hash.pl - Don Yang (uguu.org) # # 04/27/08 use strict; # Trivial hash function. Not good for most cryptographic use, but # generates enough randomness for our purpose. sub Hash($$) { my ($hash, $str) = @_; foreach my $c (unpack 'C*', $str) { $hash = ($hash << 4) ^ ($hash << 1) ^ $c; } return $hash & 0xffffffff; } # Find a usable seed. "Usable" meaning there is some 00, 01, 10, 11 # sequence available at the same bit positions. for(my $seed = -99; $seed <= 99; $seed++) { my $z = Hash($seed, ""); # 11 my $a = Hash($seed, "blackstar"); # 00 my $b = Hash($seed, "soul"); # 01 my $c = Hash($seed, "tsubaki"); # 10 my $d = Hash($seed, "maka"); # 11 my $diff1 = Hash($seed, "a"); my $diff2 = Hash($seed, "z"); my $diff3 = Hash($seed, "aa"); my $diff4 = Hash($seed, "aaa"); # Find 2 consecutive 00 bits from XOR all. This is because # 00^01^10^11 == 00. my $all = $a ^ $b ^ $c ^ $d; for(my $i = 0; $i < 31; $i++) { if( (($all >> $i) & 3) == 0 ) { # Check that expected bit patterns can be found at each hash if( (($z >> $i) & 3) == 3 && (($a >> $i) & 3) == 0 && (($b >> $i) & 3) == 1 && (($c >> $i) & 3) == 2 && (($d >> $i) & 3) == 3 && $diff1 != $diff2 && $diff2 != $diff3 && $diff1 != $diff3 && $diff3 != $diff4 && $diff1 != $diff4 && $diff2 != $diff4 ) { print "seed = $seed, bit = $i\n"; } } } }