Mathematical and cryptographic functions in solidity
Solidity provides a few inbuilt functions for performing mathematical and cryptographic operations. These functions can be used for a variety of tasks, including hash calculation and public key retrieval.
In this recipe, you will learn to use some of the common functions in solidity for performing mathematical and cryptographic tasks.
Getting ready
You need to have a working Ethereum installation for deploying and testing the smart contract. You can also use the Remix IDE to write and test solidity code.
It is required to have a basic knowledge of solidity to understand this recipe. Go through Chapter 2, Smart Contract Development, for more information.
How to do it...
- To calculate the SHA-3 (
keccak-256
) hash of something, use thekeccak256/sha3
function:
keccak256(...) // OR sha3(...) // alias to keccak256
- The function returns the hash in bytes32 format:
keccak256(...) returns (bytes32);
- Since the arguments to this functions are concatenated without...