小编Tig*_*oop的帖子

从ECDSA公钥生成比特币地址

我正在使用OpenSSL在C++中编写简单的代码来生成有效的比特币地址 - 私钥对.

我正在使用此代码段从给定的十六进制形式的私钥生成公钥:

#include <stdio.h>
#include <stdlib.h>
#include <openssl/ec.h>
#include <openssl/obj_mac.h>
#include <openssl/bn.h>

int main()
{
     EC_KEY *eckey = NULL;
     EC_POINT *pub_key = NULL;
     const EC_GROUP *group = NULL;
     BIGNUM start;
     BIGNUM *res;
     BN_CTX *ctx;



     BN_init(&start);
     ctx = BN_CTX_new(); // ctx is an optional buffer to save time from allocating and deallocating memory whenever required

     res = &start;
     BN_hex2bn(&res,"30caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683");
     eckey = EC_KEY_new_by_curve_name(NID_secp256k1);
     group = EC_KEY_get0_group(eckey);
     pub_key = EC_POINT_new(group);

     EC_KEY_set_private_key(eckey, res);

     /* pub_key is a new uninitialized `EC_POINT*`.  priv_key res …
Run Code Online (Sandbox Code Playgroud)

c c++ openssl bitcoin

9
推荐指数
1
解决办法
8388
查看次数

将PHP翻译成Python(Rest-API连接)

我正在学习Python,作为练习,我尝试制作一个程序来在比特币市场上进行交易:https://bitcurex.com.以下是API参考:https://bitcurex.com/reading-room/API.有一个PHP客户端示例,所以我尝试将其转换为Python,所以我得到:

import math
import time
import simplejson
import urllib
import urllib2
import hmac,hashlib

def microtime():
    return '%f %d' % math.modf(time.time())

def query( path, key, secret, data={} ):
    mt = microtime().split()
    nonce = mt[1] + mt[0][2:]
    data['nonce'] = nonce

    post_data = urllib.urlencode( data )

    sign = hmac.new( secret.decode('base64'), post_data, hashlib.sha512 ).digest()

    headers = {'Rest-Key' : key,
               'Rest-Sign': sign.encode('base64').strip(),
               'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
               'Content-type': 'application/x-www-form-urlencoded'}
    print headers

    url = 'https://bitcurex.com/api/0/' …
Run Code Online (Sandbox Code Playgroud)

php python python-2.7 bitcoin

5
推荐指数
0
解决办法
1007
查看次数

虚函数和向量迭代器

我在使用这段特定代码时遇到了麻烦:虚拟函数似乎无法正常工作.

#include <cstdio>
#include <string>
#include <vector>

class CPolygon
{
protected:
    std::string name;
public:
    CPolygon()
    {
        this->name = "Polygon";
    }
    virtual void Print()
    {
        printf("From CPolygon: %s\n", this->name.c_str());
    }
};

class CRectangle: public CPolygon
{
public:
    CRectangle()
    {
        this->name = "Rectangle";
    }
    virtual void Print()
    {
        printf("From CRectangle: %s\n", this->name.c_str());
    }
};

class CTriangle: public CPolygon
{
public:
    CTriangle()
    {
        this->name = "Triangle";
    }
    virtual void Print()
    {
        printf("From CTriangle: %s\n", this->name.c_str());
    }
};

int main()
{
    CRectangle rect;
    CTriangle …
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
1
解决办法
1045
查看次数

标签 统计

bitcoin ×2

c++ ×2

c ×1

openssl ×1

php ×1

python ×1

python-2.7 ×1