Best script/pseudocode to convert xpriv to xpub?
If you are comfortable with using the command line then libbitcoin-explorer is a great utility for converting your bitcoin HD keys. It even works completely offline. 

Once you have bx installed, you can run the hd-to-public command like so:

$ bx hd-to-public xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi
=&gt; xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8


More info about the other HD Key related commands for libbitcoin-explorer can be found here: https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-hd-to-public