<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Pearson_hashing</id>
	<title>Pearson hashing - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Pearson_hashing"/>
	<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Pearson_hashing&amp;action=history"/>
	<updated>2026-05-15T09:33:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>http://en.zaoniao.it/index.php?title=Pearson_hashing&amp;diff=6319&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;{{#seo: |title=Pearson hashing algorithm in Python, C – zaoniaoWiki |keywords=Pearson hashing, C, python, table, algorithm, calculator, online |description=Pearson hashing i...&quot;</title>
		<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Pearson_hashing&amp;diff=6319&amp;oldid=prev"/>
		<updated>2019-06-26T09:58:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{#seo: |title=Pearson hashing algorithm in Python, C – zaoniaoWiki |keywords=Pearson hashing, C, python, table, algorithm, calculator, online |description=Pearson hashing i...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{#seo:&lt;br /&gt;
|title=Pearson hashing algorithm in Python, C – zaoniaoWiki&lt;br /&gt;
|keywords=Pearson hashing, C, python, table, algorithm, calculator, online&lt;br /&gt;
|description=Pearson hashing is a hash function designed for fast execution on processors with 8-bit registers. Given an input consisting of any number of bytes, it produces as output a single byte that is strongly dependent E.g., applying the algorithm on the strings ABC and AEC will never produce the same value.&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;amp/&amp;gt;&lt;br /&gt;
'''Pearson hashing''' is a [[hash function]] designed for fast execution on processors with 8-bit registers. Given an input consisting of any number of bytes, it produces as output a single byte that is strongly dependent E.g., applying the algorithm on the strings ABC and AEC will never produce the same value.&lt;br /&gt;
&lt;br /&gt;
One of its drawbacks when compared with other hashing algorithms designed for 8-bit processors is the suggested 256 byte lookup table, which can be prohibitively large for a small microcontroller with a program memory size on the order of hundreds of bytes. A workaround to this is to use a simple permutation function instead of a table stored in program memory. However, using a too simple function, such as &amp;lt;code&amp;gt;T[i] = 255-i&amp;lt;/code&amp;gt; partly defeats the usability as a hash function as anagrams will result in the same hash value; using a too complex function, on the other hand, will affect speed negatively. Using a function rather than a table also allows extending the block size. Such function naturally have to be bijective, like their Pearson table variants.&lt;br /&gt;
&lt;br /&gt;
The algorithm can be described by the following pseudocode, which computes the hash of message&amp;amp;nbsp;''C'' using the permutation table&amp;amp;nbsp;''T'':&lt;br /&gt;
&lt;br /&gt;
 h := 0&lt;br /&gt;
 '''for each''' c '''in''' C '''loop'''&lt;br /&gt;
 h := T[ h '''xor''' c ]&lt;br /&gt;
 '''end loop'''&lt;br /&gt;
 '''return''' h&lt;br /&gt;
&lt;br /&gt;
== Python implementation to generate a (pseudo) 8-bit output ==&lt;br /&gt;
The 'table' parameter requires a pseudo-randomly shuffled list of range [0..255]. This may easily be generated by using python's builtin range function, and using random.shuffle to mutate it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot; line&amp;gt;&lt;br /&gt;
from random import shuffle&lt;br /&gt;
&lt;br /&gt;
example_table = range(0, 256)&lt;br /&gt;
shuffle(example_table)&lt;br /&gt;
&lt;br /&gt;
def hash8(message, table):&lt;br /&gt;
 hash = len(message) % 256&lt;br /&gt;
 for i in message:&lt;br /&gt;
 hash = table[(hash+ord(i)) % 256]&lt;br /&gt;
 return hash&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C implementation to generate 64-bit (16 hex chars) hash==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot; line&amp;gt;&lt;br /&gt;
 void Pearson16(const unsigned char *x, size_t len, &lt;br /&gt;
 char *hex, size_t hexlen) &lt;br /&gt;
 {&lt;br /&gt;
 size_t i;&lt;br /&gt;
 size_t j;&lt;br /&gt;
 unsigned char h;&lt;br /&gt;
 unsigned char hh[8];&lt;br /&gt;
 static const unsigned char T[256] = {&lt;br /&gt;
 // 0-255 shuffled in any (random) order suffices&lt;br /&gt;
 98, 6, 85,150, 36, 23,112,164,135,207,169, 5, 26, 64,165,219, // 1&lt;br /&gt;
 61, 20, 68, 89,130, 63, 52,102, 24,229,132,245, 80,216,195,115, // 2&lt;br /&gt;
 90,168,156,203,177,120, 2,190,188, 7,100,185,174,243,162, 10, // 3&lt;br /&gt;
 237, 18,253,225, 8,208,172,244,255,126,101, 79,145,235,228,121, // 4&lt;br /&gt;
 123,251, 67,250,161, 0,107, 97,241,111,181, 82,249, 33, 69, 55, // 5&lt;br /&gt;
 59,153, 29, 9,213,167, 84, 93, 30, 46, 94, 75,151,114, 73,222, // 6&lt;br /&gt;
 197, 96,210, 45, 16,227,248,202, 51,152,252,125, 81,206,215,186, // 7&lt;br /&gt;
 39,158,178,187,131,136, 1, 49, 50, 17,141, 91, 47,129, 60, 99, // 8&lt;br /&gt;
 154, 35, 86,171,105, 34, 38,200,147, 58, 77,118,173,246, 76,254, // 9&lt;br /&gt;
 133,232,196,144,198,124, 53, 4,108, 74,223,234,134,230,157,139, // 10&lt;br /&gt;
 189,205,199,128,176, 19,211,236,127,192,231, 70,233, 88,146, 44, // 11&lt;br /&gt;
 183,201, 22, 83, 13,214,116,109,159, 32, 95,226,140,220, 57, 12, // 12&lt;br /&gt;
 221, 31,209,182,143, 92,149,184,148, 62,113, 65, 37, 27,106,166, // 13&lt;br /&gt;
 3, 14,204, 72, 21, 41, 56, 66, 28,193, 40,217, 25, 54,179,117, // 14&lt;br /&gt;
 238, 87,240,155,180,170,242,212,191,163, 78,218,137,194,175,110, // 15&lt;br /&gt;
 43,119,224, 71,122,142, 42,160,104, 48,247,103, 15, 11,138,239 // 16&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
 for (j = 0; j &amp;lt; 8; ++j) {&lt;br /&gt;
 h = T[(x[0] + j) % 256];&lt;br /&gt;
 for (i = 1; i &amp;lt; len; ++i) {&lt;br /&gt;
 h = T[h ^ x[i]];&lt;br /&gt;
 }&lt;br /&gt;
 hh[j] = h;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 snprintf(hex, hexlen, &amp;quot;%02X%02X%02X%02X%02X%02X%02X%02X&amp;quot;,&lt;br /&gt;
 hh[0], hh[1], hh[2], hh[3],&lt;br /&gt;
 hh[4], hh[5], hh[6], hh[7]);&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a given string or chunk of data, Pearson's original algorithm produces only an 8 bit byte or integer, 0-255. But the Pearson hashing algorithm makes it extremely easy to generate whatever length of hash is desired. The scheme used above is a very straightforward implementation of the algorithm. As Pearson noted: a change to any bit in the string causes his algorithm to create a completely different hash (0-255). In the code above, following every completion of the inner loop, the first byte of the string is incremented by one.&lt;br /&gt;
&lt;br /&gt;
Every time that simple change to the first byte of the data is made, a different Pearson [[hash]], is generated. xPear16 builds a 16 hex character hash by concatenating a series of 8-bit Pearson () hashes. Instead of producing a value from 0 to 255, it generates a value from 0 to 18,446,744,073,709,551,615.&lt;br /&gt;
&lt;br /&gt;
Pearson's algorithm can be made to generate hashes of any desired length, simply by adding 1 to the first byte of the string, re-computing h for the string, and concatenating the results. Thus the same core logic can be made to generate 32-bit or 128-bit hashes.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Cryptographic hash function]]&lt;br /&gt;
* [[SHA-256]]&lt;br /&gt;
* [[ERC-721]]&lt;br /&gt;
* [[Polkadot]]&lt;br /&gt;
* [[Hamming code]]&lt;br /&gt;
&lt;br /&gt;
==Sources==&lt;br /&gt;
[http://wikipedia.org/ http://wikipedia.org/]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
		
	</entry>
</feed>