Advertisement
dvaskjdk1233

Untitled

Nov 21st, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. # Various bash bitcoin tools
  2. #
  3. # requires dc, the unix desktop calculator (which should be included in the
  4. # 'bc' package)
  5. #
  6. # This script requires bash version 4 or above.
  7. #
  8. # This script uses GNU tools. It is therefore not guaranted to work on a POSIX
  9. # system.
  10. #
  11. # Copyright (C) 2013 Lucien Grondin (grondilu@yahoo.fr)
  12. #
  13. # Permission is hereby granted, free of charge, to any person obtaining a copy
  14. # of this software and associated documentation files (the "Software"), to deal
  15. # in the Software without restriction, including without limitation the rights
  16. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. # copies of the Software, and to permit persons to whom the Software is
  18. # furnished to do so, subject to the following conditions:
  19. #
  20. # The above copyright notice and this permission notice shall be included in
  21. # all copies or substantial portions of the Software.
  22. #
  23. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29. # SOFTWARE.
  30.  
  31. if ((BASH_VERSINFO[0] < 4))
  32. then
  33. echo "This script requires bash version 4 or above." >&2
  34. exit 1
  35. fi
  36.  
  37. pack() {
  38. echo -n "$1" |
  39. xxd -r -p
  40. }
  41. unpack() {
  42. local line
  43. xxd -p |
  44. while read line; do echo -n ${line/\\/}; done
  45. }
  46.  
  47. declare -a base58=(
  48. 1 2 3 4 5 6 7 8 9
  49. A B C D E F G H J K L M N P Q R S T U V W X Y Z
  50. 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
  51. )
  52. unset dcr; for i in {0..57}; do dcr+="${i}s${base58[i]}"; done
  53. declare ec_dc='
  54. I16i7sb0sa[[_1*lm1-*lm%q]Std0>tlm%Lts#]s%[Smddl%x-lm/rl%xLms#]s~
  55. 483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
  56. 79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
  57. 2 100^d14551231950B75FC4402DA1732FC9BEBF-so1000003D1-ddspsm*+sGi
  58. [_1*l%x]s_[+l%x]s+[*l%x]s*[-l%x]s-[l%xsclmsd1su0sv0sr1st[q]SQ[lc
  59. 0=Qldlcl~xlcsdscsqlrlqlu*-ltlqlv*-lulvstsrsvsulXx]dSXxLXs#LQs#lr
  60. l%x]sI[lpSm[+q]S0d0=0lpl~xsydsxd*3*lal+x2ly*lIx*l%xdsld*2lx*l-xd
  61. lxrl-xlll*xlyl-xrlp*+Lms#L0s#]sD[lpSm[+q]S0[2;AlDxq]Sdd0=0rd0=0d
  62. 2:Alp~1:A0:Ad2:Blp~1:B0:B2;A2;B=d[0q]Sx2;A0;B1;Bl_xrlm*+=x0;A0;B
  63. l-xlIxdsi1;A1;Bl-xl*xdsld*0;Al-x0;Bl-xd0;Arl-xlll*x1;Al-xrlp*+L0
  64. s#Lds#Lxs#Lms#]sA[rs.0r[rl.lAxr]SP[q]sQ[d0!<Qd2%1=P2/l.lDxs.lLx]
  65. dSLxs#LPs#LQs#]sM[lpd1+4/r|]sR
  66. ';
  67.  
  68. decodeBase58() {
  69. local line
  70. echo -n "$1" | sed -e's/^\(1*\).*/\1/' -e's/1/00/g' | tr -d '\n'
  71. dc -e "$dcr 16o0$(sed 's/./ 58*l&+/g' <<<$1)p" |
  72. while read line; do echo -n ${line/\\/}; done
  73. }
  74. encodeBase58() {
  75. local n
  76. echo -n "$1" | sed -e's/^\(\(00\)*\).*/\1/' -e's/00/1/g' | tr -d '\n'
  77. dc -e "16i ${1^^} [3A ~r d0<x]dsxx +f" |
  78. while read -r n; do echo -n "${base58[n]}"; done
  79. }
  80.  
  81. checksum() {
  82. pack "$1" |
  83. openssl dgst -sha256 -binary |
  84. openssl dgst -sha256 -binary |
  85. unpack |
  86. head -c 8
  87. }
  88.  
  89. checkBitcoinAddress() {
  90. if [[ "$1" =~ ^[$(IFS= ; echo "${base58[*]}")]+$ ]]
  91. then
  92. local h="$(decodeBase58 "$1")"
  93. checksum "${h:0:-8}" | grep -qi "^${h:${#h}-8}$"
  94. else return 2
  95. fi
  96. }
  97.  
  98. hash160() {
  99. openssl dgst -sha256 -binary |
  100. openssl dgst -rmd160 -binary |
  101. unpack
  102. }
  103.  
  104. hexToAddress() {
  105. local x="$(printf "%2s%${3:-40}s" ${2:-00} $1 | sed 's/ /0/g')"
  106. encodeBase58 "$x$(checksum "$x")"
  107. echo
  108. }
  109.  
  110. newBitcoinKey() {
  111. if [[ "$1" =~ ^[5KL] ]] && checkBitcoinAddress "$1"
  112. then
  113. local decoded="$(decodeBase58 "$1")"
  114. if [[ "$decoded" =~ ^80([0-9A-F]{64})(01)?[0-9A-F]{8}$ ]]
  115. then $FUNCNAME "0x${BASH_REMATCH[1]}"
  116. fi
  117. elif [[ "$1" =~ ^[0-9]+$ ]]
  118. then $FUNCNAME "0x$(dc -e "16o$1p")"
  119. elif [[ "${1^^}" =~ ^0X([0-9A-F]{1,64})$ ]]
  120. then
  121. local exponent="${BASH_REMATCH[1]}"
  122. local uncompressed_wif="$(hexToAddress "$exponent" 80 64)"
  123. local compressed_wif="$(hexToAddress "${exponent}01" 80 66)"
  124. dc -e "$ec_dc lG I16i${exponent^^}ri lMx 16olm~ n[ ]nn" |
  125. {
  126. read y x
  127. X="$(printf "%64s" $x| sed 's/ /0/g')"
  128. Y="$(printf "%64s" $y| sed 's/ /0/g')"
  129. if [[ "$y" =~ [02468ACE]$ ]]
  130. then y_parity="02"
  131. else y_parity="03"
  132. fi
  133. uncompressed_addr="$(hexToAddress "$(pack "04$X$Y" | hash160)")"
  134. compressed_addr="$(hexToAddress "$(pack "$y_parity$X" | hash160)")"
  135. #echo ---
  136. #echo "secret exponent: 0x$exponent"
  137. #echo "public key:"
  138. #echo " X: $X"
  139. #echo " Y: $Y"
  140. #echo "compressed:"
  141. #echo " WIF: $compressed_wif"
  142. #echo " bitcoin address: $compressed_addr"
  143. #echo "uncompressed:"
  144. #echo "Generated random key:"
  145. #echo " WIF (private key): $uncompressed_wif"
  146. #echo " public bitcoin address: $uncompressed_addr"
  147. #echo Downloading info about $uncompressed_addr
  148. wget -q https://www.blockchain.com/btc/address/$uncompressed_addr
  149. if [[ $(cat $uncompressed_addr | grep final_balance) =~ ">0 BTC" ]]
  150. then
  151. : #echo "0 BTC - zero balance..."
  152. else
  153. echo "WOW!!!!! found some btc"
  154. cat $uncompressed_addr | grep final_balance
  155. echo " WIF (private key): $uncompressed_wif" >> found.txt
  156. echo " public bitcoin address: $uncompressed_addr" >> found.txt
  157. echo $(cat $uncompressed_addr | grep final_balance) >> found.txt
  158. echo "~~~~~~~~~~~~" >> found.txt
  159. read -p "Saved to found.txt. Press enter to continue"
  160. fi
  161. rm $uncompressed_addr
  162. }
  163. elif test -z "$1"
  164. then $FUNCNAME "0x$(openssl rand -rand <(date +%s%N; ps -ef) -hex 32 2>&-)"
  165. else
  166. echo unknown key format "$1" >&2
  167. return 2
  168. fi
  169. }
  170.  
  171. vanityAddressFromPublicPoint() {
  172. if [[ "$1" =~ ^04([0-9A-F]{64})([0-9A-F]{64})$ ]]
  173. then
  174. dc <<<"$ec_dc 16o
  175. 0 ${BASH_REMATCH[1]} ${BASH_REMATCH[2]} rlp*+
  176. [lGlAxdlm~rn[ ]nn[ ]nr1+prlLx]dsLx
  177. " |
  178. while read -r x y n
  179. do
  180. local public_key="$(printf "04%64s%64s" $x $y | sed 's/ /0/g')"
  181. local h="$(pack "$public_key" | hash160)"
  182. local addr="$(hexToAddress "$h")"
  183. if [[ "$addr" =~ "$2" ]]
  184. then
  185. echo "FOUND! $n: $addr"
  186. return
  187. else echo "$n: $addr"
  188. fi
  189. done
  190. else
  191. echo unexpected format for public point >&2
  192. return 1
  193. fi
  194. }
  195.  
  196. echo -n "">>found.txt
  197.  
  198. counter=0
  199. while true
  200. do
  201. echo -ne "$pc%\033[0K\rChecked: $counter keys. Press [CTRL+C] to stop.."
  202. newBitcoinKey
  203. counter=$((counter+1))
  204. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement