1. This just a Proof of Concept.
  2. NO, VBA can't be used to create BitCoin.
  3. NO, not even a very basic (or any type of) production block chain can be run on VBA. 
  4. NO, this example doesn't have peer to peer share code, consensus algorithm, or data serialization/storage code.

 
'Class Block to hold all the individual block details.
'Name : clsBlock
Option Explicit
Private m_lCounter As Long
Private m_lCreationTime As Double
Private m_sData As String
Private m_sPrevHash As String
Private m_sCurrHash As String
Private m_lNonce As Long
 
Public Property Get Counter() As Long
    Counter = m_lCounter
End Property
 
Public Property Get CreationTime() As Double
CreationTime = m_lCreationTime
End Property
 
Public Property Get Data() As String
    Data = m_sData
End Property
 
Public Property Get PrevHash() As String
    PrevHash = m_sPrevHash
End Property
 
Public Property Get CurrHash() As String
    CurrHash = GenerateHash
End Property
 
Public Property Get Nonce() As Long
    Nonce = m_lNonce
End Property
 
Public Property Let Nonce(ByVal lNewValue As Long)
    m_lNonce = lNewValue
End Property
 
Public Property Let CurrHash(ByVal sNewValue As String)
    m_sCurrHash = sNewValue
End Property
 
Public Property Let PrevHash(ByVal sNewValue As String)
    m_sPrevHash = sNewValue
End Property
 
Public Property Let Data(ByVal sNewValue As String)
    m_sData = sNewValue
End Property
 
Public Property Let CreationTime(ByVal lNewValue As Double)
    m_lCreationTime = lNewValue
End Property
 
Public Property Let Counter(ByVal lNewValue As Long)
    m_lCounter = lNewValue
End Property
 
Public Function Init(ctr As Long, crtTime As Double,  _
   blockData As String, Optional previousHash As String = "")
    Me.Counter = ctr
    Me.CreationTime = crtTime
    Me.Data = blockData
    Me.PrevHash = previousHash
    Me.CurrHash = GenerateHash
    Me.Nonce = 0
End Function
 
Public Function GenerateHash() As String   
    Dim oSHA As New clsHash   
    GenerateHash = oSHA.SHA256(CStr(Me.Counter) & Me.PrevHash & _
             CStr(Me.CreationTime) & Me.Data & CStr(Me.Nonce))       
End Function
 
Public Sub ProofOfWork(Difficulty As Long)   
    While (Mid(Me.CurrHash, 1, Difficulty) <> String(Difficulty, "0"))
        Me.Nonce = Me.Nonce + 1
         Me.CurrHash = GenerateHash
    Wend   
End Sub
 
 
'Class Block to hold/create the chain of all the individual blocks
'Name : clsBlockChain
Option Explicit
 
Private m_lDifficulty               As Long
Private m_oChain                    As Collection
 
Public Property Get Difficulty() As Long
    Difficulty = m_lDifficulty
End Property
 
Public Property Let Difficulty(ByVal lNewValue As Long)
    m_lDifficulty = lNewValue
End Property
 
Public Property Get Chain() As Collection
    Set Chain = m_oChain
End Property
 
Public Property Set Chain(ByVal oNewValue As Collection)
    Set m_oChain = oNewValue
End Property
 
Private Sub Class_Initialize()
    Dim block As New clsBlock
   
    Me.Difficulty = 3
    Set Me.Chain = New Collection
   
    Call block.Init(0, CDbl(Now()), "Genesis Block")
    Me.Chain.Add block
End Sub
 
Private Function GetLastBlock() As clsBlock
    Dim block   As clsBlock
    Dim lCtr    As Long
   
    If Me.Chain.Count >= 1 Then
        Set block = Me.Chain(Me.Chain.Count)
    End If
   
    Set GetLastBlock = block
End Function
 
Public Sub AddBlock(block As clsBlock)
    block.PrevHash = GetLastBlock().CurrHash
    block.CurrHash = block.GenerateHash
    block.ProofOfWork Me.Difficulty
    Me.Chain.Add block
End Sub
 
Public Function Validate() As Boolean
 
    Dim bRes    As Boolean
    Dim lCtr    As Long
   
    bRes = True
   
    For lCtr = 2 To Me.Chain.Count
        If (Me.Chain(lCtr).CurrHash <> Me.Chain(lCtr).GenerateHash) Then
            bRes = False
            Exit For
        End If
        If (Me.Chain(lCtr).PrevHash <> Me.Chain(lCtr - 1).CurrHash) Then
            bRes = False
            Exit For
        End If
    Next
   
    Validate = bRes
End Function
 
'Class Hash to hold SHA256 function for hashing.
'Name : clsHash
Option Explicit
 
Public Function SHA256(sIn As String, Optional bB64 As Boolean = 0) As String
    'Set a reference to mscorlib 4.0 64-bit
   
    'Test with empty string input:
    '64 Hex:   e3b0c44298f...etc
    '44 Base-64:   47DEQpj8HBSa+/...etc
   
    Dim oT As Object, oSHA256 As Object
    Dim TextToHash() As Byte, bytes() As Byte
   
    Set oT = CreateObject("System.Text.UTF8Encoding")
    Set oSHA256 = CreateObject("System.Security.Cryptography.SHA256Managed")
   
    TextToHash = oT.GetBytes_4(sIn)
    bytes = oSHA256.ComputeHash_2((TextToHash))
   
    If bB64 = True Then
       SHA256 = ConvToBase64String(bytes)
    Else
       SHA256 = ConvToHexString(bytes)
    End If
   
    Set oT = Nothing
    Set oSHA256 = Nothing
   
End Function
 
Private Function ConvToBase64String(vIn As Variant) As Variant
 
    Dim oD As Object
     
    Set oD = CreateObject("MSXML2.DOMDocument")
      With oD
        .LoadXML "<root />"
        .DocumentElement.DataType = "bin.base64"
        .DocumentElement.nodeTypedValue = vIn
      End With
    ConvToBase64String = Replace(oD.DocumentElement.Text, vbLf, "")
   
    Set oD = Nothing
 
End Function
 
Private Function ConvToHexString(vIn As Variant) As Variant
 
    Dim oD As Object
     
    Set oD = CreateObject("MSXML2.DOMDocument")
     
      With oD
        .LoadXML "<root />"
        .DocumentElement.DataType = "bin.Hex"
        .DocumentElement.nodeTypedValue = vIn
      End With
    ConvToHexString = Replace(oD.DocumentElement.Text, vbLf, "")
   
    Set oD = Nothing
 
End Function
 
'Test module to just run a quick test
'Name :mdlTest
Option Explicit
 
Public Sub BlockChainTest()
   
    Dim blockchain As clsBlockChain
    Dim Block1     As New clsBlock
    Dim Block2     As New clsBlock
       
    Set blockchain = New clsBlockChain
   
    '/ Well! VBA lacks cosntructors
    Call Block1.Init(1, CDbl(Now()), "First Block")
    Call Block2.Init(2, CDbl(Now()), "Second Block")
   
    blockchain.AddBlock Block1
    Debug.Print "New Block added. " & Block1.CurrHash
    blockchain.AddBlock Block2
    Debug.Print "New Block added. " & Block2.CurrHash
   
    '/ Validation Test
    Call ValidationTest(blockchain)
   
    '/ tamper data
    blockchain.Chain(1).Data = "Tampered"
   
    '/ Validation Test after tampering
    Call ValidationTest(blockchain)
   
     
End Sub
 
Private Sub ValidationTest(blockchain As clsBlockChain)
    If Not blockchain.Validate Then
        Debug.Print "Validation failed."
    Else
        Debug.Print "Validation passed."
    End If
End Sub
 
Credits:
    
[출처] 
http://ashuvba.blogspot.com/2018/02/blockchain-extremely-basic-example-of.html

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
858 (엑셀vba)EncodeUrl, DecodeUrl 졸리운_곰 2019.12.27 96
857 [Excel] [VBA] VBA 인터넷 프로그래밍 file 졸리운_곰 2019.12.27 721
856 Perl과 한글 file 졸리운_곰 2019.12.25 138
855 짱! 한글 (한글언어) 자연어처리 Awesome-Korean-NLP 졸리운_곰 2019.12.24 499
854 2시간 반만에 펄 익히기 : become perl programmer by only 2 hours! 졸리운_곰 2019.12.24 83
853 온라인 업무 진행을 위한 기획서 목차 졸리운_곰 2019.12.19 79
852 웹기획 절차 / 기획서 목차 졸리운_곰 2019.12.19 77
851 표준 제안서 목차 졸리운_곰 2019.12.12 76
850 IT 제안서 작성 프로세스와 기법 file 졸리운_곰 2019.12.12 117
849 NLP 참고 인터넷 문서 정리 [자연어처리] [한글 자연언어처리] 졸리운_곰 2019.12.11 2224
848 아마존 클라우드 사용법 file 졸리운_곰 2019.12.11 202
847 Aws GPU 인스턴스를 이용해 딥러닝 환경 구축하기 file 졸리운_곰 2019.12.11 155
» BlockChain: An extremely basic example of BlockChain in Excel - VBA file 졸리운_곰 2019.11.23 65
845 Eclipse Public License 2.0 졸리운_곰 2019.11.18 80
844 [SCORE] Eclipse Public License 1.0 졸리운_곰 2019.11.18 334
843 Top 10 Trending Artificial Intelligence Frameworks and Libraries file 졸리운_곰 2019.11.18 185
842 CYC 프로젝트 : 고대인의 인공지능 프로젝트 졸리운_곰 2019.11.15 98
841 Windows 환경에서 port forwarding 구현하기 file 졸리운_곰 2019.11.06 82
840 윈도우 포트포워딩을 이용한 사설 네트워크 접속 file 졸리운_곰 2019.11.06 103
839 Windows에서 포트 포워딩(Port Forwarding) 설정하기 - Netsh 졸리운_곰 2019.11.06 311
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED