Bitcoin Forum
December 04, 2016, 01:56:14 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: « 1 2 3 [4]  All
  Print  
Author Topic: A full shell script implementation of bitcoin ?  (Read 13022 times)
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
July 19, 2011, 01:50:57 PM
 #61

I've been rediscovering Perl recently.  It's the coolest programming language I know.

Code:
#!/usr/bin/perl
use strict;
use warnings;

use Digest::SHA qw(sha256);

my @base58 = (1 .. 9, 'A' .. 'H', 'J' .. 'N', 'P' .. 'Z', 'a' .. 'k', 'm' .. 'z');
my $base58 = join '', @base58;

sub decodeBase58($) {
    my $_ = shift;
    die "wrong format" if not m{^[$base58]+$};
    for my $c (0..57) { s/$base58[$c]/ $c/g }
    s/ /+58*/g;
    return qx{dc -e "16o0d$_+n"};
}

sub encodeBase58($) {
    my $_ = uc shift;
    open my $bc, qq[echo "ibase=16; n=$_; while(n>0) { n%3A; n/=3A }" | bc |];
    return join '', map { $base58[$_] } (reverse <$bc>);
}

sub checksum($) { return uc unpack 'H8', sha256 sha256 pack 'H*', shift }

sub checkBitcoinAddress($) {
    my $address = shift;
    die "wrong format" if $address !~ qr(^[$base58]{34,35}$);
    (my $h = sprintf "%50s", decodeBase58 $address) =~ tr/ /0/;

    (checksum substr $h, 0, -8) eq substr $h, -8;
}

sub hash160($) {
    # I have to use the shell here for there is no rmd160 in Digest:: :-(
    my $h = shift;
    open my $sh, qq{
    echo -n "$h" |
    openssl dgst -sha256 -binary |
    openssl dgst -rmd160 -binary |
    };
    return uc unpack 'H*', <$sh>;
}

sub hash160ToAddress($) {
    my $_ = shift;
    my $checksum = checksum "00$_";
    $_ = sprintf "%34s", encodeBase58 "00$_$checksum";
    tr/ /1/;
    return $_;
}

sub publicKeyToAddress($) {
    # Couldn't find a Perl library for ECDSA,
    # so I use the shell here.
    my $_ = shift;
    return hash160ToAddress hash160 qx{
    echo "$_" |
    openssl ec -pubin -pubout -outform DER 2>&- |
    tail -c 65
    }
}
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480816574
Hero Member
*
Offline Offline

Posts: 1480816574

View Profile Personal Message (Offline)

Ignore
1480816574
Reply with quote  #2

1480816574
Report to moderator
bji
Member
**
Offline Offline

Activity: 112


View Profile
July 20, 2011, 05:56:29 PM
 #62

I've been rediscovering Perl recently.  It's the coolest programming language I know.

Do I like Perl?  No, I hate perl.  It is sometimes acceptable when used in a very limited way for short-lived scripts intended to accomplish an immediate goal.  Perl code should be written, used once or twice, and then thrown away.
mcqueenorama
Jr. Member
*
Offline Offline

Activity: 34


View Profile
August 31, 2011, 09:37:56 PM
 #63

I see on your github only a small subset of the things discussed in this thread.  How is this going?  Have you put it up somewhere?  I want to see it!
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
September 01, 2011, 12:46:40 PM
 #64

I see on your github only a small subset of the things discussed in this thread.  How is this going?  Have you put it up somewhere?  I want to see it!

Sorry but I haven't got used to github as I basically don't like using it.  Also I don't have a permanent internet access, and I don't think about updating it when I connect.

Sorry but you'll have to extract the code from this thread.
Un zafado cualquiera
Full Member
***
Offline Offline

Activity: 159


aquí dice algo personal.


View Profile
September 02, 2011, 05:23:21 AM
 #65

All of this is very impressive. Someone made a wiki?
Pages: « 1 2 3 [4]  All
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!