SHA3 Sum

How to perform SHA3 sum of your string in Node.js, Ruby and Bash.

Node.js

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

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

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

< Back to all the stories I had written

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.