1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      golang[32]-區(qū)塊鏈-base58-創(chuàng)新互聯(lián)

      base58

      Base58是用于Bitcoin中使用的一種獨(dú)特的編碼方式,主要用于產(chǎn)生Bitcoin的錢包地址。相比Base64,Base58不使用數(shù)字"0",字母大寫"O",字母大寫"I",和字母小寫"l",以及"+“和”/"符號。

      成都創(chuàng)新互聯(lián)長期為上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為萬寧企業(yè)提供專業(yè)的成都做網(wǎng)站、成都網(wǎng)站建設(shè),萬寧網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

      設(shè)計(jì)Base58主要的目的是:
      避免混淆。在某些字體下,數(shù)字0和字母大寫O,以及字母大寫I和字母小寫l會(huì)非常相似。
      不使用"+“和”/"的原因是非字母或數(shù)字的字符串作為帳號較難被接受。
      沒有標(biāo)點(diǎn)符號,通常不會(huì)被從中間分行。
      大部分的軟件支持雙擊選擇整個(gè)字符串。

      base58編碼

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      package main

      import (
      "math/big"
      "fmt"
      )

      //切片存儲(chǔ)base58字母
      var b58Alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")


      func Base58Encode(input []byte) []byte{
      //定義一個(gè)字節(jié)切片,返回值
      var result []byte

      //把字節(jié)數(shù)組input轉(zhuǎn)化為了大整數(shù)big.Int
      x:= big.NewInt(0).SetBytes(input)

      //長度58的大整數(shù)
      base := big.NewInt(int64(len(b58Alphabet)))
       //0的大整數(shù)
      zero := big.NewInt(0)
      //大整數(shù)的指針
      mod := &big.Int{}

       //循環(huán),不停地對x取余數(shù),大小為58
      for x.Cmp(zero) != 0 {
      x.DivMod(x,base,mod)  // 對x取余數(shù)

         //講余數(shù)添加到數(shù)組當(dāng)中
      result =  append(result, b58Alphabet[mod.Int64()])
      }


      //反轉(zhuǎn)字節(jié)數(shù)組
      ReverseBytes(result)

      //如果這個(gè)字節(jié)數(shù)組的前面為字節(jié)0,會(huì)把它替換為1.
      for _,b:=range input{

      if b ==0x00{
      result =  append([]byte{b58Alphabet[0]},result...)
      }else{
      break
      }
      }


      return result

      }

      //反轉(zhuǎn)字節(jié)數(shù)組
      func ReverseBytes(data []byte){
      for i,j :=0,len(data) - 1;idata[i],data[j] = data[j],data[i]
      }
      }

      //測試 反轉(zhuǎn)操作
      func main(){
      org := []byte("qwerty")
      fmt.Println(string(org))

      ReverseBytes(org)

      fmt.Println(string(org))
      //測試編碼
       fmt.Printf("%s",string( Base58Encode([]byte("hello jonson"))))
      }

      解碼

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      func Base58Decode(input []byte) []byte{
      result :=  big.NewInt(0)
      zeroBytes :=0
      for _,b :=range input{
      if b=='1'{
      zeroBytes++
      }else{
      break
      }
      }

      payload:= input[zeroBytes:]

      for _,b := range payload{
      charIndex := bytes.IndexByte(b58Alphabet,b)  //反推出余數(shù)

      result.Mul(result,big.NewInt(58))   //之前的結(jié)果乘以58

      result.Add(result,big.NewInt(int64(charIndex)))  //加上這個(gè)余數(shù)

      }

      decoded :=result.Bytes()


      decoded =  append(bytes.Repeat([]byte{0x00},zeroBytes),decoded...)
      return decoded
      }

      完整代碼

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      100
      101
      102
      103
      104
      105
      package main

      import (
      "math/big"
      "fmt"
      "bytes"
      )

      var b58Alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")


      func Base58Encode(input []byte) []byte{
      var result []byte

      x:= big.NewInt(0).SetBytes(input)

      base := big.NewInt(int64(len(b58Alphabet)))
      zero := big.NewInt(0)

      mod := &big.Int{}
      for x.Cmp(zero) != 0 {
      x.DivMod(x,base,mod)  // 對x取余數(shù)
      result =  append(result, b58Alphabet[mod.Int64()])
      }



      ReverseBytes(result)

      for _,b:=range input{

      if b ==0x00{
      result =  append([]byte{b58Alphabet[0]},result...)
      }else{
      break
      }
      }


      return result

      }







      func Base58Decode(input []byte) []byte{
      result :=  big.NewInt(0)
      zeroBytes :=0
      for _,b :=range input{
      if b=='1'{
      zeroBytes++
      }else{
      break
      }
      }

      payload:= input[zeroBytes:]

      for _,b := range payload{
      charIndex := bytes.IndexByte(b58Alphabet,b)  //反推出余數(shù)

      result.Mul(result,big.NewInt(58))   //之前的結(jié)果乘以58

      result.Add(result,big.NewInt(int64(charIndex)))  //加上這個(gè)余數(shù)

      }

      decoded :=result.Bytes()


      decoded =  append(bytes.Repeat([]byte{0x00},zeroBytes),decoded...)
      return decoded
      }





      func ReverseBytes(data []byte){
      for i,j :=0,len(data) - 1;idata[i],data[j] = data[j],data[i]
      }
      }

      func main(){
      org := []byte("qwerty")
      fmt.Println(string(org))

      ReverseBytes(org)

      fmt.Println(string(org))



      fmt.Printf("%s\n",string( Base58Encode([]byte("hello jonson"))))




      fmt.Printf("%s",string(Base58Decode([]byte("2yGEbwRFyav6CimZ7"))))
      }

      參考資料

      (比特幣wiki-base58編碼)[https://en.bitcoin.it/wiki/Base58Check_encoding#Version_bytes]
      (維基百科-base58編碼)[https://zh.wikipedia.org/wiki/Base58]

      • 本文鏈接: https://dreamerjonson.com/2018/12/05/golang-32-base58/

      • 版權(quán)聲明: 本博客所有文章除特別聲明外,均采用 CC BY 4.0 CN協(xié)議 許可協(xié)議。轉(zhuǎn)載請注明出處!

      golang[32]-區(qū)塊鏈-base58

      創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。


      分享標(biāo)題:golang[32]-區(qū)塊鏈-base58-創(chuàng)新互聯(lián)
      瀏覽路徑:http://www.ef60e0e.cn/article/cecjdo.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        凤山县| 兰考县| 巩义市| 林周县| 建瓯市| 枞阳县| 贡嘎县| 奉节县| 佛教| 沅江市| 墨竹工卡县| 定安县| 洪洞县| 大丰市| 贵州省| 马龙县| 平安县| 玛多县| 清流县| 桦甸市| 叶城县| 信宜市| 庆城县| 正定县| 濮阳市| 盐津县| 林周县| 泰安市| 莲花县| 泰和县| 乌兰浩特市| 永昌县| 开远市| 正蓝旗| 和龙市| 江孜县| 米泉市| 牙克石市| 五台县| 依安县| 夏河县|