#!/bin/sh

echo_n(){
  echo "$@" | awk '{printf "%s",$0}'
}

echo "Please enter at least 5 characters as a unique"
echo "key for some encryption used for authenticating"
echo "the client to the server."
k=" "
while [ `echo "$k"|wc -c` -lt 5 ] ; do
  echo " "
  echo_n "Key: "
  k=`awk '{print;exit 0}'`
  if [ `echo "$k"|wc -c` -lt 5 ] ; then
    echo " "
    echo "Please enter AT LEAST FIVE characters."
  fi
done

h=`echo "$k" | od -b | head -1 | awk '{ s=0; for(i=0;i<=4;i++){ b=0; for(j=1;j<=3;j++){ b=(b*8)+substr($(i+2),j,1)} s=((s*95)+b-32)%2147483647} printf "%x\n",s}'`

/bin/rm -f cryptkey.h
echo "#define	ACCESSKEY	0x$h" > cryptkey.h

k=`echo "$k"|sed 's#\\\\#\\\\\\\\#g'|sed 's#"#\\\\"#g'`
echo "#define	ACCESSKEYSTRING	"'"'"$k"'"' >> cryptkey.h
