% hash(s,largeprime) returns an integer hash value between 1 and largeprime
% for character string s. (Note: this is not a good hash function for
% cryptographic purposes.  Search MATLAB "hash" for something better.)

% For some reason, in some versions of MATLAB this runs insanely slowly --- 
% 12 to 15 seconds for a 9 character string.

function h = hash(s,largeprime)
   fac = 256;
   h = 0;
   for i=1:length(s)
     h = rem(h*fac+double(s(i)),largeprime);
   end
   h=h+1;
end
