This file contains hidden or 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
| // Method for comparing two strings and returning true if they have same letters | |
| public static boolean sameLetters(String a, String b) { | |
| if (a == null) | |
| return b == null; | |
| if (b == null) | |
| return false; | |
| char[] left = a.toCharArray(); | |
| char[] right = b.toCharArray(); |
This file contains hidden or 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
| // Method for loading words from assets | |
| public static void loadWords(Context context) { | |
| BufferedReader buf = null; | |
| try { | |
| buf = new BufferedReader(new InputStreamReader(context.getAssets().open(DICT))); | |
| String line = null; | |
| // we read file line by line to store words |
This file contains hidden or 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
| var blockchain = new Blockchain(4); | |
| var block1 = blockchain.newBlock("Second Block"); | |
| blockchain.addBlock(block1); | |
| var block2 = blockchain.newBlock("Third Block"); | |
| blockchain.addBlock(block2); | |
| var block3 = blockchain.newBlock("Fourth Block"); | |
| blockchain.addBlock(block3); | |
| console.log("Blockchain Validity: " + blockchain.isBlockchainValid()); |
This file contains hidden or 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
| var blockchain = new Blockchain(4); | |
| var block1 = blockchain.newBlock("Second Block"); | |
| blockchain.addBlock(block1); | |
| var block2 = blockchain.newBlock("Third Block"); | |
| blockchain.addBlock(block2); | |
| var block3 = blockchain.newBlock("Fourth Block"); | |
| blockchain.addBlock(block3); | |
| console.log("Blockchain Validity: " + blockchain.isBlockchainValid()); |
This file contains hidden or 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
| class Blockchain { | |
| constructor(difficulty) { | |
| this.difficulty = difficulty; | |
| this.blocks = []; | |
| // Add Genesis Block | |
| var genesisBlock = new Block(0, null, Date.now(), "Genesis block"); | |
| genesisBlock.mineBlock(this.difficulty); | |
| this.blocks.push(genesisBlock); | |
| } | |
| } |
This file contains hidden or 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
| class Blockchain { | |
| constructor(difficulty) { | |
| this.difficulty = difficulty; | |
| this.blocks = []; | |
| // Add Genesis Block | |
| var genesisBlock = new Block(0, null, Date.now(), "Genesis block"); | |
| genesisBlock.mineBlock(this.difficulty); | |
| this.blocks.push(genesisBlock); | |
| } | |
| } |
This file contains hidden or 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
| class Blockchain { | |
| constructor(difficulty) { | |
| this.difficulty = difficulty; | |
| this.blocks = []; | |
| } | |
| } |
This file contains hidden or 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
| Block.prototype.mineBlock = function(difficulty) { | |
| this.nonce = 0; | |
| var zeros = "0".repeat(difficulty); | |
| while (this.hash.substring(0, difficulty) != zeros) { | |
| this.nonce++; | |
| this.hash = calculateHash(this); | |
| } | |
| }; |
This file contains hidden or 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
| function calculateHash(block) { | |
| return sha256(block.index + block.previousHash + | |
| block.timestamp + block.data + | |
| block.nonce); | |
| } |
This file contains hidden or 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
| class Block { | |
| constructor(index, previousHash, timestamp, data) { | |
| this.index = index; | |
| this.previousHash = previousHash; | |
| this.timestamp = timestamp; | |
| this.data = data; | |
| this.nonce = 0; | |
| this.hash = calculateHash(this); // defined later | |
| } | |
| } |