What is the math behind a private key BASE58 (P2PKH) Using this link I can understand something about a private key BASE58 (P2PKH):
&quot;such encodings will always yield a 51-character string that starts with '5', or more specifically, either '5H', '5J', or '5K'.&quot;
So let's say I have this model of private key:
5J1111111111111111111111111111111111110111111222222
I know that is not a valid private key because I can use a website such as bitaddress to tell me about this.
Taking a private key like this, I would like to understand how I can verify if it is valid, what the procedures are, because I would like to write a script to play around with this.
Keep in mind I don't have any other information, just a string like that.
Taking a private key like this, I would like to understand how I can verify if it is valid, what the procedures are, because I would like to write a script to play around with this.


Check if the string has valid Base-58 characters (123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz)
Decode the string to get the byte array using Base-58 encoding while removing and validating its checksum (last 4 bytes). Refer to the wiki link you posted for details.
Take the first byte and check if it is using the expected (version) value (128 for MainNet, 239 for TestNet).
Check the remaining data length (without first byte):
4.1. If it is 32 bytes, that is the key
4.2. If it is 33 bytes, remove last byte and check if it is equal to 1, the rest is the key
4.3. If the length is anything else, it is invalid
Convert the 32 bytes you have from step 4 to a 256-bit integer using big-endian definition
The value of step 5 has to be &gt;= 1 and &lt;= 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140