Score:4

very smooth hash (VSH) Stepwise examples

kr flag

Can someone please point me to or give me stepwise example of VSH hash function. I couldn't find an example or a reference implementation. I tried to go through original publication but it seems way too cryptic to me.

Score:3
ru flag

Here's a small example. We'll set $k=8$ so that we can hash messages of up to $2^8-1=255$ bits. We note that the eight smallest primes are $p_1=2, p_2=3$, $p_3=5,\ldots p_8=19$. We'll also pick a "hard to factor" number $n=314159265358979323$ (note that it is not actually necessary to know the factors of $n$).

To hash the 60-bit number $x$ 100110000111101011110010110011111110010111101110000110010100 we divide it into blocks of eight bits: 10011000 01111010 11110010 11001111 11100101 11101110 00011001 0100; pad the last block with zeros: 10011000 01111010 11110010 11001111 11100101 11101110 00011001 01000000 and add a final block representing the length: 10011000 01111010 11110010 11001111 11100101 11101110 00011001 01000000 00111100.

The VSH of $x$ is $p_1^{e_1}\cdots p_8^{e_8}\mod n$ where the $e_i$ is constructed by taking the $i$th least significant bit of each block and concatenating. Thus $e_1$ is the leftmost bits of each block $000110100=52$, similarly for $e_2$ we have $011101000=232$, $e_3=57$, $e_4=429$, $e_5=453$, $e_6=217$, $e_7=250$ and $e_8=376$ and so $$VSH(x)=2^{52}3^{232}5^{57}7^{429}11^{453}13^{217}17^{250}19^{376}\mod n$$ $$= 200591979525226314$$

Computation of the hash can be made ore efficient and pipelined by what is effectively a use of Shamir's trick. To do this we start with an initial value 1 mod $n$, then use each block to determine a subset of small primes to multiply our value but, followed by a square of our value. Thus we start $x_0=1$, our first block is 10011000 which selects the primes $p_8, p_5, p_4=19,11,7$ and compute $$x_1=x_0^2\times(7\times 11\times 19)\mod n=1463$$ the next block is 01111010 which selects the primes 3,7,11,13,17 so that $$x_2=x_1^2\times(3\times7\times11\times13\times 17)\mod n=109267977819$$ followed by $$x_3=x_2^2\times(3\times11\times13\times17\times19)\mod n=25314401756605599$$ and $$x_4=251897391984383465$$ $$x_5=259626239061055217$$ $$x_6=190834175947594433$$ $$x_7=249101195160685902$$ $$x_8=78295427833839690$$ $$x_9=200591979525226314$$ and so on, eventually getting the same answer as above for $x_9$.

Shivendra Mishra avatar
kr flag
Thanks for the answer. I believe x is 58 bits and not 60 bits. Did I miss something? Samir's trick seems interesting.
Daniel S avatar
ru flag
Apologies, I have appended two zeros to $x$ so that the length is now correct.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.