0

Is it possible for sha1 hashes to end with zero bytes?

Python Code

hash = haslib.sha1();
hash.update(STRING THAT RESULTS IN ZERO BYTES);
if hash.digest().endswith('\x00\x00\x00'):
....
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
themz
  • 15
  • 3
  • This property is for SHA-256 actually used in bitcoin mining (although I think BC hashes are tested to start with zero bits, but as either bit is as likely to be 0 that doesn't matter much). – Maarten Bodewes Nov 28 '15 at 23:05

1 Answers1

1

Yes, since hash function outputs are supposed to be uniformly distributed you have a non-zero chance of getting any supported output. The chance for seeing the last 24 bits (3 byte) as zero is 1.0/(2**24) or 5.9 * 10-8. On average you will have to try 223 random strings to find one with this property. Since hashing is pretty fast, this shouldn't take longer than a couple of minutes (although, Python might be a bit slow in general).

Artjom B.
  • 61,146
  • 24
  • 125
  • 222