Advertisement
noler89

Untitled

Aug 26th, 2017
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  1. pragma solidity ^0.4.2;
  2.  
  3. contract bitcoinkeys {
  4.  
  5. uint256 constant gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798;
  6. uint256 constant gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8;
  7. uint256 constant n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;
  8. uint256 constant a = 0;
  9. uint256 constant b = 7;
  10.  
  11. function bitcoinkeys(){}
  12.  
  13. // function _add (uint256 x1,uint256 z1, uint256 x2,uint256 z2) private constant returns(uint256 x3,uint256 z3){
  14. // (x3, z3) = (addmod(mulmod(z2, x1, n), mulmod(x2, z1, n), n), mulmod(z1, z2, n));
  15. // }
  16.  
  17. // function _sub (uint256 x1,uint256 z1, uint256 x2,uint256 z2) private constant returns(uint256 x3,uint256 z3){
  18. // (x3, z3) = (addmod(mulmod(z2, x1, n),mulmod(n-x2, z1, n), n), mulmod(z1, z2 , n));
  19. // }
  20.  
  21. // function _multiply (uint256 x1,uint256 z1, uint256 x2,uint256 z2) private constant returns(uint256 x3,uint256 z3){
  22. // (x3, z3) = (mulmod(x1, x2 , n), mulmod(z1, z2 , n));
  23. // }
  24.  
  25. // function _divide (uint256 x1,uint256 z1, uint256 x2,uint256 z2) private constant returns(uint256 x3,uint256 z3){
  26. // (x3, z3) = (mulmod(x1, z2 , n), mulmod(z1 , x2 , n));
  27. // }
  28.  
  29. // function inv (uint256 a) private constant returns(uint256 invA){
  30. // uint256 t=0;
  31. // uint256 newT=1;
  32. // uint256 r=n;
  33. // uint256 newR=a;
  34. // uint256 q;
  35. // while (newR != 0) {
  36. // q = r / newR;
  37.  
  38. // (t, newT) = (newT, addmod(t , (n - mulmod(q, newT,n)) , n));
  39. // (r, newR) = (newR, r - q * newR );
  40. // }
  41.  
  42. // return t;
  43. // }
  44.  
  45. // function Add (uint256 x1,uint256 y1,uint256 z1, uint256 x2,uint256 y2,uint256 z2) private constant returns(uint256 x3,uint256 y3,uint256 z3) {
  46. // uint256 l;
  47. // uint256 lz;
  48. // uint256 da;
  49. // uint256 db;
  50.  
  51. // if ((x1==0)&&(y1==0)) {
  52. // return (x2,y2,z2);
  53. // }
  54.  
  55. // if ((x2==0)&&(y2==0)) {
  56. // return (x1,y1,z1);
  57. // }
  58.  
  59. // if ((x1==x2)&&(y1==y2)) {
  60. // (l,lz) = _multiply(x1, z1, x1, z1);
  61. // (l,lz) = _multiply(l, lz, 3, 1);
  62. // (l,lz) = _add(l, lz, a, 1);
  63.  
  64. // (da,db) = _multiply(y1, z1, 2, 1);
  65. // }
  66. // else {
  67. // (l,lz) = _sub(y2, z2, y1, z1);
  68. // (da,db) = _sub(x2, z2, x1, z1);
  69. // }
  70.  
  71. // (l, lz) = _divide(l, lz, da, db);
  72.  
  73. // (x3, da) = _multiply(l, lz, l, lz);
  74. // (x3, da) = _sub(x3, da, x1, z1);
  75. // (x3, da) = _sub(x3, da, x2, z2);
  76.  
  77. // (y3, db) = _sub(x1, z1, x3, da);
  78. // (y3, db) = _multiply(y3, db, l, lz );
  79. // (y3, db) = _sub(y3, db, y1, z1 );
  80.  
  81.  
  82. // if (da != db) {
  83. // x3 = mulmod(x3, db, n);
  84. // y3 = mulmod(y3, da, n);
  85. // z3 = mulmod(da, db, n);
  86. // } else {
  87. // z3 = da;
  88. // }
  89.  
  90. // }
  91.  
  92. // function Double(uint256 x1,uint256 y1,uint256 z1) private constant returns(uint256 x3,uint256 y3,uint256 z3){
  93. // (x3,y3,z3) = Add(x1,y1,z1,x1,y1,z1);
  94. // }
  95.  
  96. // function Mulultiply(uint256 d, uint256 x1,uint256 y1,uint256 z1) private constant returns(uint256 x3,uint256 y3,uint256 z3){
  97. // uint256 remaining = d;
  98. // uint256 px = x1;
  99. // uint256 py = y1;
  100. // uint256 pz = z1;
  101. // uint256 acx = 0;
  102. // uint256 acy = 0;
  103. // uint256 acz = 1;
  104.  
  105. // if (d==0) {
  106. // return (0,0,1);
  107. // }
  108.  
  109. // while (remaining != 0) {
  110. // if ((remaining & 1) != 0) {
  111. // (acx,acy,acz) = Add(acx,acy,acz, px,py,pz);
  112. // }
  113. // remaining = remaining / 2;
  114. // (px,py,pz) = Double(px,py,pz);
  115. // }
  116.  
  117. // (x3,y3,z3) = (acx,acy,acz);
  118. // }
  119.  
  120. // function privkey_to_public(uint256 privKey) private constant returns(uint256 qx, uint256 qy){
  121. // uint256 x;
  122. // uint256 y;
  123. // uint256 z;
  124. // (x,y,z) = Mulultiply(privKey, gx, gy, 1);
  125. // z = inv(z);
  126. // qx = mulmod(x , z ,n);
  127. // qy = mulmod(y , z ,n);
  128. // }
  129.  
  130. // function randomPriv() private returns (uint256){
  131. // uint256 lastBlockNumber = block.number - 1;
  132. // uint256 hashVal = uint256(block.blockhash(lastBlockNumber));
  133. // return uint256(hashVal) + 1;
  134. // }
  135.  
  136. function dec_hex(uint256 a) public returns(string ans){
  137. string memory num;
  138. ans="";
  139. if(a==0) return "0";
  140. while(a>0){
  141. num=hex_val(a%16);
  142. ans=stringAdd(num,ans);
  143. a=a/16;
  144. }
  145. return ans;
  146. }
  147.  
  148. function hex_dec(string _s) public returns(uint ans){
  149. ans=0;
  150. bytes memory s = bytes(_s);
  151. string memory i_hate_solidity = new string(1);
  152. bytes memory solidity_is_shit = bytes(i_hate_solidity);
  153. // for(uint i= s.length-1;i>=0;i=i-1){
  154. for(uint i= 0;i<s.length;i++){
  155. solidity_is_shit[0]=s[i];
  156. ans=ans+ (16**(s.length-1-i))*dec_val(solidity_is_shit);
  157.  
  158. }
  159. }
  160.  
  161. function hex_val(uint a) private returns(string){
  162. if(a==0) return "0";
  163. if(a==1) return "1";
  164. if(a==2) return "2";
  165. if(a==3) return "3";
  166. if(a==4) return "4";
  167. if(a==5) return "5";
  168. if(a==6) return "6";
  169. if(a==7) return "7";
  170. if(a==8) return "8";
  171. if(a==9) return "9";
  172. if(a==10) return "A";
  173. if(a==11) return "B";
  174. if(a==12) return "C";
  175. if(a==13) return "D";
  176. if(a==14) return "E";
  177. if(a==15) return "F";
  178. }
  179.  
  180. function dec_val(bytes a)private returns(uint){
  181. if(strequal(a,"0")) return 0;
  182. if(strequal(a,"1")) return 1;
  183. if(strequal(a,"2")) return 2;
  184. if(strequal(a,"3")) return 3;
  185. if(strequal(a,"4")) return 4;
  186. if(strequal(a,"5")) return 5;
  187. if(strequal(a,"6")) return 6;
  188. if(strequal(a,"7")) return 7;
  189. if(strequal(a,"8")) return 8;
  190. if(strequal(a,"9")) return 9;
  191. if(strequal(a,"a")) return 10;
  192. if(strequal(a,"b")) return 11;
  193. if(strequal(a,"c")) return 12;
  194. if(strequal(a,"d")) return 13;
  195. if(strequal(a,"e")) return 14;
  196. if(strequal(a,"f")) return 15;
  197. }
  198.  
  199. function strequal(bytes a,string _b) private returns(bool){
  200. bytes memory b = bytes(_b);
  201. if(a[0]==b[0]) return true;
  202. return false;
  203. }
  204.  
  205. function stringAdd(string _a,string _b) private returns(string){
  206. bytes memory a = bytes(_a);
  207. bytes memory b = bytes(_b);
  208. string memory _ab = new string(a.length + b.length);
  209. bytes memory ab = bytes(_ab);
  210. uint k = 0;
  211. for (uint i = 0; i < a.length; i++) ab[k++] = a[i];
  212. for (i = 0; i < b.length; i++) ab[k++] = b[i];
  213. return string(ab);
  214.  
  215. }
  216.  
  217. // function randomKeys() public constant returns(string , string , string){
  218. // var privkey=randomPriv();
  219. // var (pubkeyX,pubkeyY) = privkey_to_public(privkey);
  220. // return (dex_hex(privkey), dex_hex(pubkeyX), dex_hex(pubkeyY));
  221. // }
  222.  
  223. function randomaddress() public constant returns (bytes32){
  224. // string memory privkey="18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725";
  225. // string memory pubkeyX="50863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352";
  226. // string memory pubkeyY="2CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6";
  227. // var pubkey=stringAdd(pubkeyX,pubkeyY);
  228. // pubkey=stringAdd("04",pubkey);
  229.  
  230. var addr1=sha256("0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6");
  231. // var addr2=ripemd160(addr1);
  232. return addr1;
  233. //var addr3=bytesAdd("00",(addr2));
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement