WDef

Group: Members
Posts: 798
Joined: Sep. 2005 |
 |
Posted: Sep. 18 2007,12:33 |
 |
On at least one wifi network I've tried that required an ascii WEP key, the s: prefix option for dsl's iwconfig - signifying an ascii key - just would not work for me. After I used the hex equivalent instead, it connected immediately.
So I thought a converter from asci keys to hex keys might be handy.
Anyway it made a compact little homework exercise for myself, so thought I might share.
In bash:
Code Sample | #!/bin/bash # # asci2hexkey.sh # Coverts ascii key to hex on the fly
ASCIKEY="" echo "Type in ascii wifi key:" while read -s -n 1 ASCHAR; do [ "$ASCHAR" = "" ] && break printf "%X" $(printf "%d" \'"$ASCHAR"\') ASCIKEY=${ASCIKEY}${ASCHAR} done
echo " = ascii key \"$ASCIKEY\"" |
Also did it differently using perl, after googling for the gist:
Code Sample | #!/usr/bin/perl # # asci2hexkey.pl # Takes asci key as command line argument & prints hex #
use strict; use warnings;
my $asciichars = shift; chomp $asciichars;
my $hexchars = ''; foreach my $c (split(//,$asciichars)) { $hexchars .= sprintf "%x", ord($c); } print "$hexchars\n"; |
User should insert hyphens every four chars into the resulting hex key when using with iwconfig.
|