Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a SHA-1 hash be purely numeric?

Is there any chance that a SHA-1 hash can be purely numeric, or does the algorithm ensure that there must be at least one alphabetical character?

Edit: I'm representing it in base 16, as a string returned by PHP's sha1() function.

like image 425
Ryan McCue Avatar asked Jun 27 '09 09:06

Ryan McCue


People also ask

How many digits is SHA-1?

SHA-1 or Secure Hash Algorithm 1 is a cryptographic hash function which takes an input and produces a 160-bit (20-byte) hash value. This hash value is known as a message digest. This message digest is usually then rendered as a hexadecimal number which is 40 digits long.

Is SHA-1 hash unique?

SHA1 generates an almost-unique 160-bit (20-byte) signature for a text. There is a good description on Wikipedia; see below for the source code. A hash is not 'encryption' – it cannot be decrypted back to the original text (it is a 'one-way' cryptographic function, and is a fixed size for any size of source text).

How many bits is an SHA-1 hash value?

The hash size for the SHA1 algorithm is 160 bits.

Is SHA-1 hash always the same?

SHA1 is a message hashing or digest algorithm where it generates a 160-bit unique value from the input. The size of the input does not matter, because SHA1 always generates a message hash of the same size, which is 160 bits. This may seem very confusing, but the algorithm is just for that.


2 Answers

technically, a SHA1 hash is a number, it is just most often encoded in base 16 (which is what PHP's sha1() does) so that it nearly always has a letter in it. There is no guarantee of this though.

The odds of a hex encoded 160 bit number having no digits A-F are (10/16)40 or about 6.84227766 × 10-9

like image 160
cobbal Avatar answered Sep 21 '22 18:09

cobbal


The SHA-1 hash is a 160 bit number. For the ease of writing it, it is normally written in hexadecimal. Hexadecimal (base 16) digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e and f. There is nothing special about the letters. Each hexadecimal character equivalent to 4 bits which means the hash can be written in 40 characters.

I don't believe there is any reason why a SHA-1 hash can't have any letters, but it is improbable. It's like generating a 40 digit (base 10) random number and not getting any 7s, 8s or 9s.

like image 42
David Johnstone Avatar answered Sep 21 '22 18:09

David Johnstone