Electrum version 2 creates a seed from a random number which is then encoded as a mnemonic. The seed is validated by checking that the hmac begins with the bytes 01
or 101
for standard and 2fa types, respectively.
I have looked at the python code on github and indeed it does return the 01 byte but I am still confused as to how one can ensure a hash is going to start with a predicted value (01\101
).
How can this be so? Is it that I'm missing the nuance of what the code does or the concept of how hmac works