• Bang Bits in Bash (with od and rm)

    From Rick Hohensee@21:1/5 to All on Fri Aug 25 20:00:42 2023
    #Bit-Banging in Bash (with od and rm)

    # Adler32 checksum of a file with Bash, rm, and od.
    # Rick rickfordictator.com Hohensee August 2023
    # E is the checksum. Android .dex files use Adler32.
    # not checked much, but it is clearly doing binary data.

    decimalbytes ()
    {
    od -An -v -t d1 -w1 $1 >> decimal.out
    }


    Subadler () { # < decimal.out
    A=1 B=0
    while read
    do
    let A=$(($A+$REPLY))
    let A=$(($A&0xffffffff))
    let B=$B+$A
    let B=$(($B&0xffffffff))
    done
    }


    Adler32 () {
    decimalbytes $1

    Subadler < decimal.out
    rm decimal.out
    C=$((A%65521))
    D=$((B%65521))
    echo "C =" $C " D = " $D
    E=$(((D<<16)|C))
    echo $E

    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rick Hohensee@21:1/5 to Rick Hohensee on Sat Aug 26 06:43:11 2023
    On Friday, August 25, 2023 at 11:00:45 PM UTC-4, Rick Hohensee wrote:
    #Bit-Banging in Bash (with od and rm)

    # Adler32 checksum of a file with Bash, rm, and od.
    # Rick rickfordictator.com Hohensee August 2023
    # E is the checksum. Android .dex files use Adler32.
    # not checked much, but it is clearly doing binary data.

    decimalbytes ()
    {
    od -An -v -t d1 -w1 $1 >> decimal.out
    }


    Subadler () { # < decimal.out
    A=1 B=0
    while read
    do
    let A=$(($A+$REPLY))
    let A=$(($A&0xffffffff))
    let B=$B+$A
    let B=$(($B&0xffffffff))
    done
    }


    Adler32 () {
    decimalbytes $1

    Subadler < decimal.out
    rm decimal.out
    C=$((A%65521))
    D=$((B%65521))
    echo "C =" $C " D = " $D
    E=$(((D<<16)|C))

    should be E=$(((C<<16)|D))
    and the low two bytes still don't match an online example, but the high two bytes do

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)