I generate the private and the public keys in Shell like that:
openssl ecparam -name secp256k1 -rand /dev/random -genkey -noout -out private-key.pem
openssl ec -in private-key.pem -outform DER | tail -c +8 | head -c 32 | xxd -p -c 32 > bitcoin_private_key.pem
openssl ec -in private-key.pem -pubout -outform DER | tail -c 65 | xxd -p -c 65 > bitcoin_public_key.pem
Then I can take the public key X with:
head -c 66 bitcoin_public_key.pem | tail -c 64
And the last byte of Y with:
tail -c 3 bitcoin_public_key.pem
The compressed public key must be 0x02 + X for an even last byte of Y and 0x03 + X for an odd one.
How to check if the last Y's byte is odd or even?