Created
December 5, 2018 16:11
-
-
Save Alonski/e1ce34536e0848f408c6f94b508bf305 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=false&gist=
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
pragma solidity 0.4.25; | |
pragma experimental "ABIEncoderV2"; | |
contract HashTestSplit { | |
function calculateFinalHash(uint256 num1, uint256 num2) | |
public | |
pure | |
returns (bytes32) | |
{ | |
uint256 mult = num1 * num2; | |
return keccak256(abi.encodePacked(mult)); | |
} | |
function split32Hashto8(bytes32 finalHash) | |
public | |
pure | |
returns (bytes8 dice1, bytes8 dice2, bytes8 dice3, bytes8 dice4) | |
{ | |
bytes8[4] memory dice = [bytes8(0), 0, 0, 0]; | |
assembly { | |
mstore(dice, finalHash) | |
mstore(add(dice, 8), finalHash) | |
mstore(add(dice, 16), finalHash) | |
mstore(add(dice, 24), finalHash) | |
} | |
dice1 = dice[0]; | |
dice2 = dice[1]; | |
dice3 = dice[2]; | |
dice4 = dice[3]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment