How to perform SHA3 sum of your string in Node.js, Ruby and Bash.
Node.js
Assuming you already have npm installed in your Ubuntu 20.04. You’ll need to install SHA3 package with the following command.
npm install sha3
Once completed, create a file named sha3sum.js and copy the contents below into the file.
const { SHA3 } = require('sha3');
const hash = new SHA3(224);
var str = process.argv[2];
var sha3sum = hash.update(str).digest('hex');
console.log(sha3sum);
Now to test if the sha3sum.js file is working. The sha3sum.js is currently configured with 224 bits, it can be replaced with 256, 384 or 512.
node sha3sum.js 'hello world'
If it ran successfully, you should see the same output.
dfb7f18c77e928bb56faeb2da27291bd790bc1045cde45f3210bb6c5
Bash in Ubuntu 20.04
SHA3 sum is not installed by default. To install, run the following command.
sudo apt update
sudo apt install libdigest-sha3-perl -y
To perform a SHA3 sum, run the following command. To run the SHA3 sum with other bit length, replace 224 in the command with 256, 384 or 512.
echo -n 'hello world'|sha3sum -a 224|awk '{print $1}'
You should see the same output as below if it ran successfully.
dfb7f18c77e928bb56faeb2da27291bd790bc1045cde45f3210bb6c5
Ruby
To install SHA3 sum in Ruby, run the following command.
sudo gem install sha3
Once completed, create a file sha3sum.rb and copy the contents below into the file.
require 'sha3'
str=ARGV[0]
puts SHA3::Digest.hexdigest(224, str)
To test if the file is working, run the following command.
ruby sha3sum.rb 'hello world'
You should see the same output as below if it ran successfully.
dfb7f18c77e928bb56faeb2da27291bd790bc1045cde45f3210bb6c5