WDef

Group: Members
Posts: 798
Joined: Sep. 2005 |
 |
Posted: Oct. 06 2007,21:18 |
 |
Yes, I know, (groan), "he still hasn't given up on this thread".
(Pls bear with me while I post my self-education exercises).
Much easier in C:
Code Sample | //~ asci2hex - converts ascii wifi key to hex
#include <stdio.h>
main() { char ch; printf("Enter the ascii key: "); while ( ch= ' ' ){ ch = getchar(); if (ch == '\n') break; printf("%X", ch); } printf("\n"); }
|
And (todo: doesn't yet report any ignored non-hex input):
Code Sample | //~ asci2hex - converts hex wifi key to ascii
#include <stdio.h> #include <stdlib.h> #include <ctype.h>
char hexToAscii(char first, char second) //~ http://snippets.dzone.com/posts/show/2073 { char hex[3], *stop; hex[0] = first; hex[1] = second; hex[2] = 0; return strtol(hex, &stop, 16); }
main() { char ch1, ch2;
printf("Enter the hex key: "); while (1){ ch1 = getchar(); if (ch1 == '\n') break; if (!isxdigit(ch1)) continue; ch2 = getchar(); if (ch2 == '\n') break; if (!isxdigit(ch2)) continue; printf("%c", hexToAscii(ch1, ch2)); } printf("\n"); }
|
|