Bitcoin Forum
May 03, 2024, 11:07:23 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 2 3 [4]  All
  Print  
Author Topic: A full shell script implementation of bitcoin ?  (Read 14134 times)
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


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
    }
}

1714777643
Hero Member
*
Offline Offline

Posts: 1714777643

View Profile Personal Message (Offline)

Ignore
1714777643
Reply with quote  #2

1714777643
Report to moderator
1714777643
Hero Member
*
Offline Offline

Posts: 1714777643

View Profile Personal Message (Offline)

Ignore
1714777643
Reply with quote  #2

1714777643
Report to moderator
1714777643
Hero Member
*
Offline Offline

Posts: 1714777643

View Profile Personal Message (Offline)

Ignore
1714777643
Reply with quote  #2

1714777643
Report to moderator
It is a common myth that Bitcoin is ruled by a majority of miners. This is not true. Bitcoin miners "vote" on the ordering of transactions, but that's all they do. They can't vote to change the network rules.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714777643
Hero Member
*
Offline Offline

Posts: 1714777643

View Profile Personal Message (Offline)

Ignore
1714777643
Reply with quote  #2

1714777643
Report to moderator
1714777643
Hero Member
*
Offline Offline

Posts: 1714777643

View Profile Personal Message (Offline)

Ignore
1714777643
Reply with quote  #2

1714777643
Report to moderator
bji
Member
**
Offline Offline

Activity: 112
Merit: 10


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
Newbie
*
Offline Offline

Activity: 34
Merit: 0


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 (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


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: 158
Merit: 100


aquí dice algo personal.


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

All of this is very impressive. Someone made a wiki?
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
February 18, 2022, 09:49:42 PM
Merited by ABCbits (1), n0nce (1)
 #66

Sorry for necro-posting, but a github user pointed me to that thread so I felt like updating subscribers.


This project is still alive, though updates are rare.

Feel free to check it out : https://github.com/grondilu/bitcoin-bash-tools/

Pages: « 1 2 3 [4]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!