Friday, January 20, 2017

256-bit multiplication in BASH, if you have the time.

In my continuing saga of using BASH to glue programs together with bashbignumbers.sh , it takes 8 seconds to do a 128-bit multiply resulting in a 256-bit result, and 31 second for a 512-bit result.
#!/bin/bash
# Required programs:
BIGNUMBERS=bashbignumbers.sh
if [ ! -f $BIGNUMBERS ]; then
    echo "File, $BIGNUMBERS, not found!"
    exit
fi
source "$BIGNUMBERS"
TESTSTR256_0="ce6a8c03135bf12ca7ca2e748c9c3557ca564f9b69a2565f6adee7000d9236ec"
TESTSTR256_1="a325aa75a7335e84f11f80c46f0921ada9a4887620c583eff95f09e669df8634"
BINARG0=$(bashUTILhex2bin $TESTSTR256_0) 
BINARG1=$(bashUTILhex2bin $TESTSTR256_1)
start=`date +%s`
RESULTFULL=$(bashMULbinstring $BINARG0 $BINARG1)
end=`date +%s`
runtime=$((end-start))
echo "runtime: $runtime"
RESULTHEX=$(bashUTILbin2hex $RESULTFULL)
echo "$RESULTHEX"
The resulting output is:
runtime: 31
838c35fdd0424be26879b9824ca6ad38b245bbb0425da4bdf5e9a51027687da7b7def3037554f1659df8a104630f5afe5bf4a3bdaff5d7c4e3ad6209ee06aff0

No comments:

Post a Comment