Bitcoin Forum
April 26, 2024, 08:41:27 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: math/hash function question  (Read 530 times)
oinkoink (OP)
Jr. Member
*
Offline Offline

Activity: 34
Merit: 1


View Profile
November 17, 2016, 01:53:07 PM
 #1

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  Kiss
Be very wary of relying on JavaScript for security on crypto sites. The site can change the JavaScript at any time unless you take unusual precautions, and browsers are not generally known for their airtight security.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714164087
Hero Member
*
Offline Offline

Posts: 1714164087

View Profile Personal Message (Offline)

Ignore
1714164087
Reply with quote  #2

1714164087
Report to moderator
BurtW
Legendary
*
Offline Offline

Activity: 2646
Merit: 1130

All paid signature campaigns should be banned.


View Profile WWW
November 17, 2016, 07:54:06 PM
 #2

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


Our family was terrorized by Homeland Security.  Read all about it here:  http://www.jmwagner.com/ and http://www.burtw.com/  Any donations to help us recover from the $300,000 in legal fees and forced donations to the Federal Asset Forfeiture slush fund are greatly appreciated!
oinkoink (OP)
Jr. Member
*
Offline Offline

Activity: 34
Merit: 1


View Profile
November 18, 2016, 11:47:45 AM
 #3

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.
ABXORANDOR
00000
10101
01101
11011
  but im pretty sure this is nonsense anyway bc the resulting hash gets hashed again and in doing so the bits are getting shuffled nicely again. In other words: I never know what output i get from the hash function as long as i don't enter the same input.  And the only inter-dependencies i can see is that  H(A) XOR H(B) == H(B) XOR H(A) and i can not think of any resulting problem. On the other hand $toH = $H1.$H2; would result i a pretty long number and i'm not sure if this is preferable Huh
BUT you are dealing here with a total noob and there is a good chance i get a lot of this wrong ^^ 
To summarize:
  • maybe it doesn't matter how i combine the two hashes, probably the fastest method is the best method here?
  • XOR takes away the "order" of my input H(A) XOR H(B) == H(B) XOR H(A) (which is totally ok here imo)
Swtrse
Newbie
*
Offline Offline

Activity: 70
Merit: 0


View Profile
November 18, 2016, 12:06:10 PM
 #4

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.
BurtW
Legendary
*
Offline Offline

Activity: 2646
Merit: 1130

All paid signature campaigns should be banned.


View Profile WWW
November 18, 2016, 12:12:33 PM
 #5

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.

Our family was terrorized by Homeland Security.  Read all about it here:  http://www.jmwagner.com/ and http://www.burtw.com/  Any donations to help us recover from the $300,000 in legal fees and forced donations to the Federal Asset Forfeiture slush fund are greatly appreciated!
oinkoink (OP)
Jr. Member
*
Offline Offline

Activity: 34
Merit: 1


View Profile
November 18, 2016, 05:23:08 PM
 #6

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?
Swtrse
Newbie
*
Offline Offline

Activity: 70
Merit: 0


View Profile
November 21, 2016, 04:43:50 PM
 #7

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
       |
       v
00000000 = 0
00000001 = 1
00001000 = 8
00001001 = 9
As you can see in binary system odd numbers end with an '1' and even numbers end with an '0'.
% 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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!