最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++實現(xiàn)區(qū)塊鏈的源碼

 更新時間:2021年01月20日 09:48:19   作者:程序小黑  
這篇文章主要介紹了C++實現(xiàn)區(qū)塊鏈的源碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

看了上面的算法,相信大家基本可以猜到,相對于比特幣的限量的性質(zhì),對于本算法來說,難解程度的根本原因即為向量環(huán)路的迭代次數(shù)。迭代次數(shù)越多,則算法越難解,從而導(dǎo)致解題需要花費更多的時候,再基于這點,在數(shù)學(xué)上,當(dāng)解題次數(shù)足夠大時,效率會無限小,從而導(dǎo)致了解題時間無限長最后導(dǎo)致加密貨幣的發(fā)放無限小。
創(chuàng)世區(qū)塊創(chuàng)建(部分大媽在前面有實現(xiàn),而區(qū)塊這一部分將會詳細解答)

void Make_First_Block()
{
Getpublickey();
blo.data = circle;
blo.pre_hash = 0;
blo.this_hash = (blo.pre_hash+public_Key) * (a+b);
Block.push_back(blo);
}

由于在區(qū)塊鏈中,本區(qū)快的數(shù)字簽名是基于上一區(qū)塊的數(shù)字簽名和區(qū)塊本身的DATA決定, 所以,在這里我們采用了上一區(qū)塊的數(shù)字簽名加上難解的PublicKey乘上長軸和短軸的和實現(xiàn)本區(qū)塊的數(shù)字簽名的算法。
添加區(qū)塊(當(dāng)當(dāng)前區(qū)塊被算出時,添加新區(qū)塊,檢查簽名正確性。)

void Append_Block()
{
pre_blo = blo;
bool flag = true;
auto temp = public_Key;
circle = circle + 1;
Getpublickey();
blo.data = circle;
blo.pre_hash = blo.this_hash;
blo.this_hash = (blo.pre_hash + public_Key) * (a + b);
for(list::iterator itor = Block.begin(); itor != Block.end(); itor++)
{
if ((*itor).this_hash != (*itor).pre_hash + temp * (a + b))
{
flag = false;
break;
}
}
if (flag) { Block.push_back(blo); };
}

這個迭代其實可以不用的,因為我在外部還定義了一個block類型的全局變量Pre_block和blo。Pre_block存儲了上一個區(qū)塊的信息。而本區(qū)塊的信息則存儲在Blo中。只有當(dāng)用戶解出當(dāng)前區(qū)塊后,才可以得到新區(qū)塊。而data參數(shù),為了方便僅存儲了當(dāng)前區(qū)塊所在的位置。
區(qū)塊的計算(用類實現(xiàn))

class Get_Block :Create_Block {
public:
int diffcult;
int number = 1;
Get_Block():Create_Block(“OK”){
}
void calc()
{
double start = clock();
while (true){
for (unsigned long long z = 1; z < ULLONG_MAX; z++){
for (unsigned long long j = 1; j < 65535; j = j + 1) {
for (unsigned long long i = 1; i < 65535; i = i + 1) {
Cryptography *person = new Cryptography(i,j,z);
person->Getpublickey();
block bloc;
bloc.data = circle;
bloc.pre_hash = pre_blo.this_hash;
bloc.this_hash = (blo.pre_hash + person->public_Key) * (i + j);
if (blo.data == bloc.data &&blo.pre_hash== bloc.pre_hash && blo.this_hash == bloc.this_hash)
{
double end = clock();
cout << “歷時”<<end-start<<“毫秒獲得的第” << number++ <<“個區(qū)塊信息為:” << endl;
cout << “data:” << bloc.data << endl;
cout << “this_hash:” << bloc.this_hash << endl;
cout << “pre_hash:” << bloc.pre_hash << endl << “=======================” << endl << endl;
this->Append_Block();
start = clock();
}
delete []person;
}
}
}
}
}
};

完整代碼:

#include 
#include <stdio.h>
#include <windows.h>
#include 
#include 
#include 
#include 
#include <time.h>
using namespace std;

struct Moving_Point {
unsigned long long x;
unsigned long long y;
};

int circle = 1;

class Martix {
public:
static const int circle_s = 1; //假定向量環(huán)路為1;
static const int KEY =Martix::circle_s * 8;
private:
unsigned long long martix_4_2[Martix::KEY / 2][2]; //存儲向量矩陣
unsigned long long martix_8_8[Martix::KEY][Martix::KEY]; //存儲由向量矩陣得到的轉(zhuǎn)置矩陣
unsigned long long martix_complete[KEY * 2]; //存儲操作完成后的矩陣(一維)

public:
Martix(string a) {};
Martix(int a, int b,int circle)
{
int key = 8;
int cir = circle;
while (cir–)
{
martix_4_2[key / 2 - 4][0] = (-1)*b; martix_4_2[key / 2 - 4][1] = (-1)*a;
martix_4_2[key / 2 - 3][0] = b; martix_4_2[key / 2 - 3][1] = (-1)*a;
martix_4_2[key / 2 - 2][0] = b; martix_4_2[key / 2 - 2][1] = a;
martix_4_2[key / 2 - 1][0] = (-1)*b; martix_4_2[key / 2 - 1][1] = a;
key += 8;
}
}
void Change_New_Martix() {
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
martix_8_8[i][j] = 0;
}
}
for (int j = 2; j < KEY / 2 + 2; j++) {
martix_8_8[0][j] = martix_4_2[j - 2][0] * (-1);
martix_8_8[1][j] = martix_4_2[j - 2][1] * (-1);
}
for (int i = 2; i < KEY / 2 + 2; i++) {
martix_8_8[i][0] = martix_4_2[i - 2][0] * (-1);
martix_8_8[i][1] = martix_4_2[i - 2][1] * (-1);
}
for (int i = 2; i < KEY / 2 + 2; i++)
{
for (int j = 2; j < KEY / 2 + 2; j++)
{
martix_8_8[i][j] = 0;
}
}
}
public:
void Save_Martix()
{
int key = 0;
for (int i = 0; i < KEY / 2 + 2; i++)
{
for (int j = 0; j < KEY / 2 + 2; j++)
{
if (martix_8_8[i][j] != 0)
{
martix_complete[key++] = martix_8_8[i][j];
}
}
}
}
unsigned long long GetPublicKey()
{
unsigned long long public_key = martix_complete[0];
for (int i = 1; i < KEY * 2; i++)
{
if (i % 2 == 0)
{
public_key = public_key + martix_complete[i];
}
else {
public_key = public_key * martix_complete[i];
}
}
return public_key;
}
};
class Cryptography :Martix
{
public:
/作為私鑰,發(fā)送方保存內(nèi)容/
unsigned long long a; //橢圓長軸的半軸長度
unsigned long long b; //橢圓短軸的半軸長度
/作為公鑰,接收方接受公鑰/
unsigned long long public_Key; //通過橢圓矩陣算法得到的公鑰G
Moving_Point p; //隨機選定的在橢圓上的點

public:
Cryptography(string a) :Martix(“OK”) {};
Cryptography(unsigned long long in_a, unsigned long long in_b,int diffcult) :Martix(in_a, in_b,diffcult)
{
this->a = in_a;
this->b = in_b;
p.x = 0;
p.y = 0;
public_Key = Getpublickey();
}
unsigned long long Getpublickey()
{
Get_Public_Key();
return public_Key;
}
Moving_Point GetPoint()
{
Get_Point();
return p;
}
public:
void PrintPrivateKey() {
cout << “#############私鑰:#############” << endl;
cout << “長軸:” << 2this->a << “\t\t”;
cout << “短軸:” << 2this->b << endl;
}
private:
void Get_Point()
{
if (p.x == 0 && p.y == 0)
{
while (!Is_Moving_Point())
{
Get_Moving_Point_P();
}
}
}
void Get_Public_Key()
{
this->Change_New_Martix();
this->Save_Martix();
this->public_Key = this->GetPublicKey();
}
void Get_Moving_Point_P() //得到一個隨機的在橢圓上的點的坐標
{
for (int i = 0; i < this->a; i++)
{
for (int j = 0; j < this->b; j++)
{
p.x = i;
p.y = j;
}
}
}
bool Is_Moving_Point() {
if (pow(b, 2)*pow(p.y, 2) + pow(a, 2)*pow(p.x, 2) == pow(a, 2)*pow(b, 2) && p.y <= a && p.x <= b)
return true;
else
return false;
}
};
struct block {
unsigned long long this_hash;
unsigned long long pre_hash;
unsigned long long data;
};

block blo;
block pre_blo = {0,0,0};
class Create_Block:public Cryptography {
public:
list Block;
public:
Create_Block(string a):Cryptography(“OK”) {};
Create_Block(int x = rand()*2, int y = rand(), int diffcult = 1):Cryptography(x,y,diffcult){
}
void Make_First_Block()
{
Getpublickey();
blo.data = circle;
blo.pre_hash = 0;
blo.this_hash = (blo.pre_hash+public_Key) * (a+b);
Block.push_back(blo);
}
void Append_Block()
{
pre_blo = blo;
bool flag = true;
auto temp = public_Key;
circle = circle + 1;
Getpublickey();
blo.data = circle;
blo.pre_hash = blo.this_hash;
blo.this_hash = (blo.pre_hash + public_Key) * (a + b);
for(list::iterator itor = Block.begin(); itor != Block.end(); itor++)
{
if ((*itor).this_hash != (*itor).pre_hash + temp * (a + b))
{
flag = false;
break;
}
}
if (flag) { Block.push_back(blo); };
}
};

class Get_Block :Create_Block {
public:
int diffcult;
int number = 1;
Get_Block():Create_Block(“OK”){
}
void calc()
{
double start = clock();
while (true){
for (unsigned long long z = 1; z < ULLONG_MAX; z++){
for (unsigned long long j = 1; j < 65535; j = j + 1) {
for (unsigned long long i = 1; i < 65535; i = i + 1) {
Cryptography *person = new Cryptography(i,j,z);
person->Getpublickey();
block bloc;
bloc.data = circle;
bloc.pre_hash = pre_blo.this_hash;
bloc.this_hash = (blo.pre_hash + person->public_Key) * (i + j);
if (blo.data == bloc.data &&blo.pre_hash== bloc.pre_hash && blo.this_hash == bloc.this_hash)
{
double end = clock();
cout << “歷時”<<end-start<<“毫秒獲得的第” << number++ <<“個區(qū)塊信息為:” << endl;
cout << “data:” << bloc.data << endl;
cout << “this_hash:” << bloc.this_hash << endl;
cout << “pre_hash:” << bloc.pre_hash << endl << “=======================” << endl << endl;
this->Append_Block();
start = clock();
}
delete []person;
}
}
}
}
}
};

int main()
{
Create_Block * one = new Create_Block();
one->Make_First_Block();
Get_Block* two = new Get_Block();
two->calc();
return 0;
}

不得不說第一個區(qū)塊的挖掘永遠是最快的。第二個區(qū)塊確實要等好久才可以得出。以上即為C/C++實現(xiàn)區(qū)塊鏈的全部源碼。僅用于學(xué)習(xí)交流,不得用于商業(yè)用途,轉(zhuǎn)載必究。

作者:程序小黑
來源:CSDN
原文:https://blog.csdn.net/qq_27180763/article/details/82588305
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請附上博文鏈接!

到此這篇關(guān)于C++實現(xiàn)區(qū)塊鏈的源碼的文章就介紹到這了,更多相關(guān)c++區(qū)塊鏈內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C語言字符串快速壓縮算法代碼

    C語言字符串快速壓縮算法代碼

    這篇文章主要介紹了C語言字符串快速壓縮算法代碼,將字符串中連續(xù)出席的重復(fù)字母進行壓縮,其主要的壓縮字段的格式為”字符重復(fù)的次數(shù)+字符”。有需要的小伙伴參考下吧。
    2015-03-03
  • C++編程小心指針被delete兩次

    C++編程小心指針被delete兩次

    這篇文章主要介紹了C++編程指針被delete兩次的嚴重后果,以實例闡述了C++指針使用中的誤區(qū)和注意點,需要的朋友可以參考下
    2014-07-07
  • C語言一篇精通鏈表的各種操作

    C語言一篇精通鏈表的各種操作

    鏈表是一種常見的重要的數(shù)據(jù)結(jié)構(gòu)。它是動態(tài)地進行存儲分配的一種結(jié)構(gòu),是根據(jù)需要開辟內(nèi)存單元,鏈表這種數(shù)據(jù)結(jié)構(gòu),必須利用指針變量才能實現(xiàn),即一個結(jié)點中應(yīng)包含一個指針變量,用它存放下一結(jié)點的地址
    2022-04-04
  • C語言實現(xiàn)井字棋詳解

    C語言實現(xiàn)井字棋詳解

    這篇文章主要為大家介紹了C語言如何實現(xiàn)井字棋,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • C++?正則表達式的應(yīng)用詳解

    C++?正則表達式的應(yīng)用詳解

    正則表達式(regular?expression)描述了一種字符串匹配的模式(pattern),可以用來檢查一個串是否含有某種子串、將匹配的子串替換或者從某個串中取出符合某個條件的子串等
    2021-11-11
  • android studio創(chuàng)建C++項目的實現(xiàn)示例

    android studio創(chuàng)建C++項目的實現(xiàn)示例

    本文主要介紹了android studio創(chuàng)建C++項目的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • 提高C程序效率的10種有效方法

    提高C程序效率的10種有效方法

    本文向你介紹規(guī)范你的C代碼的10種方法。需要的朋友可以過來參考下,希望對大家有所幫助
    2013-10-10
  • EasyC++內(nèi)部鏈接性和無鏈接性

    EasyC++內(nèi)部鏈接性和無鏈接性

    這篇文章主要介紹了EasyC++內(nèi)部鏈接性和無鏈接性,當(dāng)我們使用static關(guān)鍵字,將變量的作用于限制在整個文件時,該變量的鏈接性為內(nèi)部鏈接性,然而無鏈接性的變量其實就是在代碼塊當(dāng)中使用static關(guān)鍵字創(chuàng)建的,接下來一起進入文章了解更多內(nèi)容吧
    2021-12-12
  • C++內(nèi)核對象封裝單實例啟動程序的類

    C++內(nèi)核對象封裝單實例啟動程序的類

    這篇文章主要介紹了利用C++內(nèi)核對象封裝的類,程序只能運行單個實例,可防止多次啟動,大家參考使用吧
    2013-11-11
  • C/C++讀寫JSON數(shù)據(jù)的詳細過程記錄

    C/C++讀寫JSON數(shù)據(jù)的詳細過程記錄

    JSON文件無論是在web開發(fā)、客戶端開發(fā)、服務(wù)端等開發(fā)中都是應(yīng)用比較廣泛的的第一種輕量級數(shù)據(jù)交換格式,非常方便閱讀和編寫,下面這篇文章主要給大家介紹了關(guān)于C/C++讀寫JSON數(shù)據(jù)的詳細過程,需要的朋友可以參考下
    2023-04-04

最新評論

玛曲县| 平定县| 专栏| 育儿| 大英县| 永嘉县| 麟游县| 巢湖市| 沛县| 栾川县| 精河县| 南城县| 河北区| 安阳县| 荆州市| 那曲县| 阿拉善左旗| 开鲁县| 婺源县| 名山县| 东兴市| 中宁县| 阿巴嘎旗| 凭祥市| 革吉县| 乌恰县| 辽阳市| 隆林| 堆龙德庆县| 恭城| 六盘水市| 黑水县| 湖北省| 张家界市| 夏津县| 中阳县| 名山县| 瑞安市| 汪清县| 五华县| 策勒县|