 Cryptography

# Is it possible that a SHA256 hash has the same hex character over and over again?

In theory, there are infinite inputs, that you can hash with SHA-256. So theoretically it would be possible that one hash string would read 0xaaaaaaaa...

But would that also be possible practically, or do the algorithms check that this is not happening? ## Solution

First of all, the output of SHA-256 is binary and consists of 32 bytes (256 denotes the output size in bits). What you are talking about is apparently the hexadecimal encoding of these bytes.

The possibility that you are talking about is called (1st) pre-image resistance (Wikipedia):

Given a hash value $$h$$, it should be difficult to find any message $$m$$ such that $$h = \text{H}(m)$$.

("difficult" is a non-technical term here, generally we use "computationally infeasible", obviously there will be messages that map to any hash value, the difficulty is finding them for a one-way hash)

No, the algorithms do not check this explicitly, because the algorithm by itself needs to be resistant against it. Furthermore, the repetition of certain bits is not that special all by itself. It would be unclear what you would need to test for.

"But would that also be possible practically" well, no, unless SHA-2 gets broken. Generally it is collision resistance that gets broken first. That means finding a hash where $$\text{H}(m) = \text{H}(m')$$ for any $$m$$ and $$m'$$. This is easier to attack because an attacker can try and find weaknesses in the algorithm that create an internal collision while controlling both $$m$$ and $$m'$$. SHA-256 is still considered secure in this regard.