#! /bin/sh # # This code is slightly convoluted. This is because I want to avoid # depending on anything not built in to sh. Most of this code is # things that must be built in to the shell, like $(( )) and for. The # only other things are [ and echo, each of which is builtin on any # even vaguely modern sh I'm aware of, and even those I use in only # minimal least-common-denominator ways. # n=0 poly=11101101101110001000001100100000 while [ $n -lt 256 ]; do v= t=$n for i in 0 1 2 3 4 5 6 7; do v=$(($t % 2))$v t=$(($t / 2)) done v=000000000000000000000000$v for i in 0 1 2 3 4 5 6 7; do case $v in *0) v=0${v%0};; *1) x1=0${v%1} x2=$poly v= while [ x$x1 != x ]; do case $x1 in 0*) case $x2 in 0*) xr=0;; *) xr=1;; esac;; *) case $x2 in 0*) xr=1;; *) xr=0;; esac;; esac v=$v$xr x1=${x1#?} x2=${x2#?} done;; esac done x=0x for i in 0 1 2 3 4 5 6 7; do case $v in 0000*) x="$x"0;; 0001*) x="$x"1;; 0010*) x="$x"2;; 0011*) x="$x"3;; 0100*) x="$x"4;; 0101*) x="$x"5;; 0110*) x="$x"6;; 0111*) x="$x"7;; 1000*) x="$x"8;; 1001*) x="$x"9;; 1010*) x="$x"a;; 1011*) x="$x"b;; 1100*) x="$x"c;; 1101*) x="$x"d;; 1110*) x="$x"e;; 1111*) x="$x"f;; esac v=${v#????} done echo $x, n=$(($n+1)) done