
Originally Posted by
Nick_the_Greek
read WEP keys --> accept only (10 or 26 ascii) or (5 or 13 hex)
As always, most of this is untested (or deliberately flawed) to make sure you have to figure it out for youself
Code:
read WEPKEY
WEPKEY=`echo $WEPKEY | cut -c 1-26`
HEXSTRIPPED=`echo $WEPKEY | sed 's/[^0-9A-F]//g'`
if [ $HEXSTRIPPED -ne $WEPKEY ];
then
# key is ASCII
SHORTASCII=`echo $WEPKEY | cut -c 1-10`
# now we have $SHORTASCII and $WEPKEY, we need to check the length
# of SHORTASCII and compare it to the length of WEPKEY. If SHORT is equal
# to 10, and wepkey is not equal to 26, then we use short, else wepkey
# unless neither are the right size, then we bail out.
# bonus side effect: we fail through to a 10char ascii key, rather than a
# 15 character ascii key
SHORTLEN=`expr length $SHORTASCII`
# etc. Same applies to HEX
else
# key is HEX
fi
The -z you are using merely checks if the variable is empty (or zero), expr length $BLAH lets you figure out the length of the variable, and the cut command is the one that lets you strip them back to the appropriate sizes.
Edit: And wahey he finally joins the ranks of Senior Members!