[identity profile] glukinho.livejournal.com posting in [community profile] useful_faq
Как считается хэш от чего-нибудь, например, файла? Или строки?

Date: 2006-02-09 08:06 pm (UTC)
From: [identity profile] a7sharp9.livejournal.com
Если вопрос в том, как это уже где-нибудь сделано, то для строчек - вот, например, способ, которым пользуется Java (из комментариев в файле String.java):

* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using int arithmetic, where s[i] is the
* ith character of the string, n is the length of
* the string, and ^ indicates exponentiation.