CS 1425 Lecture 1: Java Blockchain-Block Class

15 views3 pages

Document Summary

Java blockchain (block class) package basicblockchain; import java. security. import java. security. messagedigest; import java. util. import java. util. logging. level; import java. util. logging. logger; * @return bhash, a. k. a hash in block public string getbhash() { return bhash; //method containing algorithm for mining the blockchain with input integer. //diff used to determine difficulty of mining process (larger number = more. String a1; a1 = new string(new char[diff]). replace("\0", "0"); while (!bhash. substring(0, diff). equals(a1)) { bonce = bonce + 1; bhash = calchash(); String a = "mining complete of block:" + bhash; //turns values of a blockchain into a hash using sha-256 encryption private string calchash() { String a0 = string. valueof(bindex); a0 += string. valueof(bdate); a0 += bdata; a0 += string. valueof(bonce); a0 += blasthash; String a1; a1 = ""; try { a1 = sha256(a0); //method that turns string input into an encrypted hash using stringbuffer static string sha256(string in) throws nosuchalgorithmexception { Messagedigest encrypt = messagedigest. getinstance("sha-256"); byte[] encrypt0 = encrypt. digest(in. getbytes());

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Questions