Advertisement
Guest User

Pub2addy.sh

a guest
Jan 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #use like:
  4. #./Pub2addy.sh 02c2c5150ec7d10ebe5bbfec53d5c22cfce9fc5ba2083d6fd637cde9e999ed3b94 HUSH
  5. #
  6. # You CANNOT got the other way
  7. #
  8. # It is impossible to compute the public key of an address, as the address is computed from the hash of the public key.
  9. # You can retrieve the public key from address with the reference client using the validateaddress RPC call (or in the debug window of Bitcoin-Qt), but that simply fetches it from the wallet, and only works if the address is your.
  10. # Jun 13 '13 at 8:21
  11. # Pieter Wuille
  12.  
  13. pub="$1"
  14. addon="0"
  15. case $2 in
  16.     KMD)
  17.         prefix="60"
  18.         ;;
  19.     BTC|BCH)
  20.         prefix="00"
  21.         addon="1"
  22.         ;;
  23.     DGB|DOGE|PIVX)
  24.         prefix="30"
  25.         ;;
  26.     BTG)
  27.         prefix="38"
  28.         ;;
  29.     HUSH)
  30.         prefix="7352"
  31.         ;;
  32.     *)
  33.         prefix="60"
  34.         ;;
  35. esac
  36.  
  37. declare -a base58=(1 2 3 4 5 6 7 8 9 A B C D E F G H J K L M N P Q R S T U V W X Y Z a b c d e f g h i j k m n o p q r s t u v w x y z)
  38. encodeBase58() {                                  
  39.     local n
  40.     echo -n "$1" | sed -e's/^\(\(00\)*\).*/\1/' -e's/00/1/g' | tr -d '\n'
  41.     dc -e "16i ${1^^} [3A ~r d0<x]dsxx +f" |
  42.         while read -r n; do echo -n "${base58[n]}"; done
  43. }
  44. if [[ $addon == "1" ]] ; then
  45.     hexprefix="00"
  46. else
  47.     hexprefix=`echo "obase=16;ibase=10; ${prefix}" | bc`
  48. fi
  49.  
  50. pubsha="$(echo -n $pub \
  51. | xxd -r -p | sha256sum | awk '{print $1}')"
  52. echo "pubsha is: $pubsha"
  53. ripe="$(echo -n $pubsha \
  54. | xxd -r -p | openssl rmd160)"
  55. ripeb=${ripe#*= }
  56. echo "ripe is: $ripe"
  57. plusnet="$(echo -n $ripeb \
  58. | sed -e "s/^/$hexprefix/")"
  59. echo "plusnet is: $plusnet"
  60. shanet="$(echo -n $plusnet \
  61. | xxd -r -p | sha256sum | awk '{print $1}')"
  62. reshanet="$(echo -n $shanet \
  63. | xxd -r -p | sha256sum | awk '{print $1}')"
  64. leadbits="$(echo -n $reshanet| sed 's/^\(.\{8\}\).*/\1/')"
  65. mash="$plusnet$leadbits"
  66. echo "mash is: $mash"
  67. address="$(encodeBase58 "$mash")"
  68. echo "Address is: $address"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement