Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ [1] 2 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Convert ascii wifi key to hex< Next Oldest | Next Newest >
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Sep. 18 2007,12:33 QUOTE

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.
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Sep. 18 2007,13:55 QUOTE

Isn't it a colon after every 2 characters?  But I don't use wifi...
Anyways, I thought it might be more handy to have the ascii phrase to be passed as an argument.

Code Sample
#!/bin/bash
#
# asci2hexkey2.sh
# Accepts an ascii key and outputs the hex equivalent, delimited by colons

if [ $# -ne 1 ]; then
   exit 1
fi

FIRST=1
IFS=""

printf $1 |
while read -s -n 1 ASCHAR; do
   if [ $FIRST -eq 0 ]; then
       printf ":"
   else
       FIRST=0
   fi
   [ "$ASCHAR" = "" ] && break
   printf "%X" $(printf "%d" \'"$ASCHAR"\')
done

echo


I believe roberts did use to post a perl link that would do this as well (not sure if included in DSL).  Perhaps some kind of integration of this could be used in iwconfig?

EDIT:
- yes, I meant the gui tool in DSL instead of iwconfig
- added the reading of spaces (I think they can be used...)
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Sep. 18 2007,14:20 QUOTE

Thx for interface variant.. The interesting point for me was using bash printf to convert to ordinal then to hex.

No colon in key string for me.

I posted the perl since I did that first - but the core came out of the web - no credit to me other than googling and making it cli.  Haven't seen Robert's link.

Quote
Perhaps some kind of integration of this could be used in iwconfig?


I guess you mean in dsl's wifi setup GUI.  I never use that, but if there's a bug in iwconfig on certain ascii keys with s: perhaps either there's a fix or a 'convert to hex' button might be good.

Has anyone else had trouble with the s: option in iwconfig?  Perhaps it was just the one network ...
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Sep. 18 2007,14:40 QUOTE

So it's just the ascii key number converted to hex? Thanks, I was wondering about that..

Could you also include a reverse function in that, if it's going to DSL?


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Sep. 18 2007,14:47 QUOTE

Quote
include a reverse function


In dsl or no, if you want one I'll have a go.

Just wondering -  why would you want to convert a hex key to ascii - to make it easier to remember perhaps?
Back to top
Profile PM 
13 replies since Sep. 18 2007,12:33 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ [1] 2 3 >/
reply to topic new topic new poll
Quick Reply: Convert ascii wifi key to hex

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code