Created
March 3, 2019 04:07
-
-
Save arpi-r/0bb770208bcf45834867d275f8fba1e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib, json | |
def hash_blocks(blocks): | |
prev_hash = None | |
hashes=[] | |
for block in blocks: | |
block['prev_hash'] = prev_hash | |
block_serialized = json.dumps(block, sort_keys=True).encode('utf-8') | |
block_hash = hashlib.sha256(block_serialized).hexdigest() | |
hashes.append(block_hash) | |
prev_hash = block_hash | |
return hashes | |
bankdetails=[["all features of bank account1"],["all features of bank account2"],["all features of bank account3"]] | |
socialmedia=["image1","image2","image3"] | |
reporteddata=["pdflist","imagelist","textinputlist"] | |
data=["aadharnumber","name",bankdetails,socialmedia,reporteddata] | |
block_genesis = { | |
'prev_hash': None, | |
'transactions': data | |
} | |
block_1 = { | |
'prev_hash': None, | |
'transactions': data | |
} | |
block_2 = { | |
'prev_hash': None, | |
'transactions': data | |
} | |
print("Original hash:") | |
h1=hash_blocks([block_genesis, block_1, block_2]) | |
for i in range(len(h1)): | |
print("Block ",i,": ",h1[i]) | |
print("Tampering the data") | |
block_1['transactions'][3] = [] | |
print("Tampered hash:") | |
h2=hash_blocks([block_genesis, block_1, block_2]) | |
for i in range(len(h2)): | |
print("Block ",i,": ",h2[i]) | |
for i in range(min(len(h1),len(h2))): | |
if h1[i]!=h2[i]: | |
print("Blocks have been tampered!") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment