exp1-POWの簡単な実装

参照ビデオ
bilibili-luotuo

const sha256 = require('crypto-js/sha256')

// 对于同一个输入,只需要改变一点点内容,哈希后的结果差别很大
console.log(sha256('luotuo1').toString())
console.log(sha256('luotuo2').toString())

ここに画像の説明を挿入

//需要得到开头值为0的哈希,X是多少?
//通过改变X来得到哈希

function proofOfWork(){
    
    
  let data = 'luotuo'
  let x = 1

  while(true){
    
    
    if(sha256(data + x).toString()[0] != '0'){
    
    
      x = x +1
    }else{
    
    
      console.log(x)
      console.log(sha256(data + x).toString())
      break
    }

  }
}

proofOfWork()

ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/weixin_39333120/article/details/109351581