0

Is it possible to generate private and public keys using only a calculator? If not how many lines of code would it take to write a wallet generator, and how difficult would it be? How would you do this?

1

Bitcoin Address Generator in Obfuscated Python is a fun piece of Python 2.7 code:

_                   =r"""A(W/2,*M(3*G
               *G*V(2*J%P),G,J,G)+((M((J-T
            )*V((G-S)%P),S,T,G)if(S@(G,J))if(
         W%2@(S,T)))if(W@(S,T);H=2**256;import&h
       ashlib&as&h,os,re,bi    nascii&as&k;J$:int(
     k.b2a_hex(W),16);C$:C    (W/    58)+[W%58]if(W@
    [];X=h.new("rip           em    d160");Y$:h.sha25
   6(W).digest();I$                 d=32:I(W/256,d-1)+
  chr(W%256)if(d>0@"";                  U$:J(k.a2b_base
 64(W));f=J(os.urando       m(64))        %(H-U("AUVRIxl
Qt1/EQC2hcy/JvsA="))+      1;M$Q,R,G       :((W*W-Q-G)%P,
(W*(G+2*Q-W*W)-R)%P)       ;P=H-2**       32-977;V$Q=P,L=
1,O=0:V(Q%W,W,O-Q/W*                      L,L)if(W@O%P;S,
T=A(f,U("eb5mfvncu6                    xVoGKVzocLBwKb/Nst
zijZWfKBWxb4F5g="),      U("SDra         dyajxGVdpPv8DhEI
qP0XtEimhVQZnEfQj/       sQ1Lg="),        0,0);F$:"1"+F(W
 [1:])if(W[:1           ]=="\0"@""        .join(map(B,C(
  J(W))));K$:               F(W          +Y(Y(W))[:4]);
   X.update(Y("\4"+                     I(S)+I(T)));B$
    :re.sub("[0OIl    _]|            [^\\w]","","".jo
     in(map(chr,ra    nge    (123))))[W];print"Addre
       ss:",K("\0"+X.dig    est())+"\nPrivkey:",K(
         "\x80"+I(f))""";exec(reduce(lambda W,X:
            W.replace(*X),zip(" \n&$@",["","",
               " ","=lambda W,",")else "])

I'd check out these two Python modules:

  1. Bitcoinaddress
  2. Pybitcointools (a fantastic Bitcoin library: see the README.txt for usage)

A private key is just/can be a very large number. However it's not possible to use a calculator to calculate an address easily, mainly because:

  • modular arithmetic is involved
  • base 58 check is not a straightforward conversion
  • there's appended bytes and such

I'd recommend either this web app to get the next best thing.

  • 1
    You also need a very good source of entropy, which a calculator (nor a human) possess. Absolutely never should you be outsourcing key generation to a third party as they (and everybody else watching your connection) can easily steal your money any time in the future. – Anonymous Apr 6 '15 at 1:59
  • 1
    @Bitcoin Very good point. The only feasible way of getting entropy without a library is by rolling dice. – Wizard Of Ozzie Apr 6 '15 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.