Title: math/hash function question Post by: oinkoink on November 17, 2016, 01:53:07 PM Hi all!
lets say i take H(H(A) XOR H(B)) % 2 where A is a user input, and B .. i dunno .. lets say the valid POW hash of the next block. I'm wondering if i do get, in the long run, a 50/50 distribution of 0's and 1's and if so, is there a "simpler" or "better" approach where i can get a user input to influence the outcome in a non predictable way? merci :-* Title: Re: math/hash function question Post by: BurtW on November 17, 2016, 07:54:06 PM Just an aside this might be slightly better as it gets rid of any inter-dependencies that might be introduced by the XOR operation.
H(H(A) concatenated to H(B)) % 2 Title: Re: math/hash function question Post by: oinkoink on November 18, 2016, 11:47:45 AM so you mean just putting them together like:
$H1 = 2; $H2 = 5; $toH = $H1.$H2; echo $toH //25 i can't see how this would be better, can you point me somewhere or share your wisdom with me? my thought was that xor returns a 50/50 distribution itself if the two hashes would consist of (pseudo) random 0s and 1s.
BUT you are dealing here with a total noob and there is a good chance i get a lot of this wrong ^^ To summarize:
Title: Re: math/hash function question Post by: Swtrse on November 18, 2016, 12:06:10 PM From a statistical point of view the distribution must be 50/50.
The reason for that is the % 2 which is just an other way to determine of the least significant bit is a 0 or a 1. Since we can assume that a hash algorithm generates hashes with 0 and 1s at the last significant bit with the same frequency it is irrelevant how many hashes you chain with an XOR. The distribution will always be 50/50. If you have hash algorithm where the distribution for the hash itself is not 50/50 then the final distribution must be the average of all chained hash distributions. I hope this is somehow understandable since English is not my native language and this is really technical. Title: Re: math/hash function question Post by: BurtW on November 18, 2016, 12:12:33 PM It was just an aside. Either concatenation or xor will work for what you are trying to do. It is just that when used for security related purposes the hash function is designed to work with the concatenation of values. You are not using the hash function for a security related purpose here so either way.
Title: Re: math/hash function question Post by: oinkoink on November 18, 2016, 05:23:08 PM Thanks BurtW, Swtrse!
You are awesome! @Swtrse least significant bit? you mean, it could be also the most significant bit but choose one and watch for the distribution, right? otherwise i don't get why it hast to be the LSB? Title: Re: math/hash function question Post by: Swtrse on November 21, 2016, 04:43:50 PM Thanks BurtW, Swtrse! You are awesome! @Swtrse least significant bit? you mean, it could be also the most significant bit but choose one and watch for the distribution, right? otherwise i don't get why it hast to be the LSB? It's called least significant bit because it has the least effect on the number For examlpe Code: LSB % 2 is a way to determine if an number is odd or even taking all of that into account you only have to look at the LSB to see if an number is odd or even or from the binary view if the LSB is a 1 or a 0 |