C code, MD5 hash, if statements assistance

This is a discussion on C code, MD5 hash, if statements assistance within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { /* set variables / array */ char MAC[13]; char MACHashed; ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    16

    C code, MD5 hash, if statements assistance

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
         /* set variables / array */
        char MAC[13];
        char MACHashed;
        char WPAkey1;
    
        /* this will be fed from the iphone wifi card*/
        printf( "Please enter MAC with no colons: " );
        fgets ( MAC, 13, stdin );
    
        /* MAC need to be MD5 hashed and puit into MACHashed variable*/
        MACHashed = "572E74CDF761D0E4038509919CD8AF1A"; /*this is MD5 has of 001122334455 */
    
        if (MACHashed[1] == "5");
            WPAkey1 = E;
    
    
        /* this outputs the WPA key*/
        printf("%c", WPAkey1);
    
        getchar();
        return(0);
    I am looking to take a user input (12 characters) MD5 hash it and then split this into 16 2 charcater segments (can an array do 2 characters at a time?)

    Once I have the 16 segments, run if statments as follows so that the each of the 16 segments now turns into a Letter, i.e. if the first 2 characters of hte hash are 0F the letter woudl be P:-

    Code:
    if %array%==00	A
    if %array%==01	B
    if %array%==02	C
    if %array%==03	D
    if %array%==04	E
    if %array%==05	F
    if %array%==06	G
    if %array%==07	H
    if %array%==08	I
    if %array%==09	J
    if %array%==0A	K
    if %array%==0B	L
    if %array%==0C	M
    if %array%==0D	N
    if %array%==0E	O
    if %array%==0F	P
    if %array%==10	Q
    if %array%==11	R
    if %array%==12	S
    if %array%==13	T
    if %array%==14	U
    if %array%==15	V
    if %array%==16	W
    if %array%==17	X
    if %array%==18	Y
    if %array%==19	Z
    if %array%==1A	A
    if %array%==1B	B
    if %array%==1C	C
    if %array%==1D	D
    if %array%==1E	E
    if %array%==1F	F
    if %array%==20	G
    if %array%==21	H
    if %array%==22	I
    if %array%==23	J
    if %array%==24	K
    if %array%==25	L
    if %array%==26	M
    if %array%==27	N
    if %array%==28	O
    if %array%==29	P
    if %array%==2A	Q
    if %array%==2B	R
    if %array%==2C	S
    if %array%==2D	T
    if %array%==2E	U
    if %array%==2F	V
    if %array%==30	W
    if %array%==31	X
    if %array%==32	Y
    if %array%==33	Z
    if %array%==34	A
    if %array%==35	B
    if %array%==36	C
    if %array%==37	D
    if %array%==38	E
    if %array%==39	F
    if %array%==3A	G
    if %array%==3B	H
    if %array%==3C	I
    if %array%==3D	J
    if %array%==3E	K
    if %array%==3F	L
    if %array%==40	M
    if %array%==41	N
    if %array%==42	O
    if %array%==43	P
    if %array%==44	Q
    if %array%==45	R
    if %array%==46	S
    if %array%==47	T
    if %array%==48	U
    if %array%==49	V
    if %array%==4A	W
    if %array%==4B	X
    if %array%==4C	Y
    if %array%==4D	Z
    if %array%==4E	A
    if %array%==4F	B
    if %array%==50	C
    if %array%==51	D
    if %array%==52	E
    if %array%==53	F
    if %array%==54	G
    if %array%==55	H
    if %array%==56	I
    if %array%==57	J
    if %array%==58	K
    if %array%==59	L
    if %array%==5A	M
    if %array%==5B	N
    if %array%==5C	O
    if %array%==5D	P
    if %array%==5E	Q
    if %array%==5F	R
    if %array%==60	S
    if %array%==61	T
    if %array%==62	U
    if %array%==63	V
    if %array%==64	W
    if %array%==65	X
    if %array%==66	Y
    if %array%==67	Z
    if %array%==68	A
    if %array%==69	B
    if %array%==6A	C
    if %array%==6B	D
    if %array%==6C	E
    if %array%==6D	F
    if %array%==6E	G
    if %array%==6F	H
    if %array%==70	I
    if %array%==71	J
    if %array%==72	K
    if %array%==73	L
    if %array%==74	M
    if %array%==75	N
    if %array%==76	O
    if %array%==77	P
    if %array%==78	Q
    if %array%==79	R
    if %array%==7A	S
    if %array%==7B	T
    if %array%==7C	U
    if %array%==7D	V
    if %array%==7E	W
    if %array%==7F	X
    if %array%==80	Y
    if %array%==81	Z
    if %array%==82	A
    if %array%==83	B
    if %array%==84	C
    if %array%==85	D
    if %array%==86	E
    if %array%==87	F
    if %array%==88	G
    if %array%==89	H
    if %array%==8A	I
    if %array%==8B	J
    if %array%==8C	K
    if %array%==8D	L
    if %array%==8E	M
    if %array%==8F	N
    if %array%==90	O
    if %array%==91	P
    if %array%==92	Q
    if %array%==93	R
    if %array%==94	S
    if %array%==95	T
    if %array%==96	U
    if %array%==97	V
    if %array%==98	W
    if %array%==99	X
    if %array%==9A	Y
    if %array%==9B	Z
    if %array%==9C	A
    if %array%==9D	B
    if %array%==9E	C
    if %array%==9F	D
    if %array%==A0	E
    if %array%==A1	F
    if %array%==A2	G
    if %array%==A3	H
    if %array%==A4	I
    if %array%==A5	J
    if %array%==A6	K
    if %array%==A7	L
    if %array%==A8	M
    if %array%==A9	N
    if %array%==AA	O
    if %array%==AB	P
    if %array%==AC	Q
    if %array%==AD	R
    if %array%==AE	S
    if %array%==AF	T
    if %array%==B0	U
    if %array%==B1	V
    if %array%==B2	W
    if %array%==B3	X
    if %array%==B4	Y
    if %array%==B5	Z
    if %array%==B6	A
    if %array%==B7	B
    if %array%==B8	C
    if %array%==B9	D
    if %array%==BA	E
    if %array%==BB	F
    if %array%==BC	G
    if %array%==BD	H
    if %array%==BE	I
    if %array%==BF	J
    if %array%==C0	K
    if %array%==C1	L
    if %array%==C2	M
    if %array%==C3	N
    if %array%==C4	O
    if %array%==C5	P
    if %array%==C6	Q
    if %array%==C7	R
    if %array%==C8	S
    if %array%==C9	T
    if %array%==CA	U
    if %array%==CB	V
    if %array%==CC	W
    if %array%==CD	X
    if %array%==CE	Y
    if %array%==CF	Z
    if %array%==D0	A
    if %array%==D1	B
    if %array%==D2	C
    if %array%==D3	D
    if %array%==D4	E
    if %array%==D5	F
    if %array%==D6	G
    if %array%==D7	H
    if %array%==D8	I
    if %array%==D9	J
    if %array%==DA	K
    if %array%==DB	L
    if %array%==DC	M
    if %array%==DD	N
    if %array%==DE	O
    if %array%==DF	P
    if %array%==E0	Q
    if %array%==E1	R
    if %array%==E2	S
    if %array%==E3	T
    if %array%==E4	U
    if %array%==E5	V
    if %array%==E6	W
    if %array%==E7	X
    if %array%==E8	Y
    if %array%==E9	Z
    if %array%==EA	A
    if %array%==EB	B
    if %array%==EC	C
    if %array%==ED	D
    if %array%==EE	E
    if %array%==EF	F
    if %array%==F0	G
    if %array%==F1	H
    if %array%==F2	I
    if %array%==F3	J
    if %array%==F4	K
    if %array%==F5	L
    if %array%==F6	M
    if %array%==F7	N
    if %array%==F8	O
    if %array%==F9	P
    if %array%==FA	Q
    if %array%==FB	R
    if %array%==FC	S
    if %array%==FD	T
    if %array%==FE	U
    if %array%==FF	V
    Is this possible, the elements I am stuck on are how to MD5 within C, and how to run an if statment on a concatenated array1 and array2 character?

    Thanks for any help...

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    I would say that you should perhaps learn the C language before you start attempting to mess around with MD5 hashing and the like, because your code is fairly nonsensical. But whatever.
    First hit on a Google search of md5 C implementation

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    16
    Ok I have read alittle more and got so far (see code)

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
        /*search for SKYxxxxx and MD5 hash the MAC address and input this into variable MACHashed*/
    
        const char* MACHashed = "572E74CDF761D0E4038509919CD8AF1A";
    
        /*variables set*/
        char *WPAkey1 = (char*) malloc(3);
        char *WPAkey2 = (char*) malloc(3);
        char *WPAkey3 = (char*) malloc(3);
        char *WPAkey4 = (char*) malloc(3);
        char *WPAkey5 = (char*) malloc(3);
        char *WPAkey6 = (char*) malloc(3);
        char *WPAkey7 = (char*) malloc(3);
        char *WPAkey8 = (char*) malloc(3);
        char WPAkeya;
        char WPAkeyb;
        char WPAkeyc;
        char WPAkeyd;
        char WPAkeye;
        char WPAkeyf;
        char WPAkeyg;
        char WPAkeyh;
    
        /*set WPAkey characters 1-8 based on MACHashed*/
        strncpy(WPAkey1, MACHashed+2, 2);
        strncpy(WPAkey2, MACHashed+6, 2);
        strncpy(WPAkey3, MACHashed+10, 2);
        strncpy(WPAkey4, MACHashed+14, 2);
        strncpy(WPAkey5, MACHashed+18, 2);
        strncpy(WPAkey6, MACHashed+22, 2);
        strncpy(WPAkey7, MACHashed+26, 2);
        strncpy(WPAkey8, MACHashed+30, 2);
    
        /* this outputs the HEX codes*/
        printf(WPAkey1);printf("\n");printf(WPAkey2);printf("\n");printf(WPAkey3);printf("\n");printf(
    The output has ">" after each HEX code? Why woudl that be?

    Any assistance appreciated!!

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Because strncpy() does not append a \0 automatically for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    16
    I tried different combinations to remove the > (\0) from the WPAkey1 etc variables but with no joy....

    If strncpy isnt capable of setting a variable from a string without >, is there another command I could utilse?

    I need the WPAKey1 etc variables to purely be 2 characters to allow the remaining program to work properly.... thanks for any help....

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    strncpy(WPAkey1, MACHashed+2, 2);
    WPAkey1[2] = '\0';

    Is that too much?

    Maybe you could create your own my_strncpy_which_appends_a_nul() function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 03-08-2010, 10:30 AM
  2. Help understanding Hash Table
    By boblettoj99 in forum C Programming
    Replies: 3
    Last Post: 12-29-2009, 12:23 PM
  3. Hello,i need assistance in completing the code
    By toader in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2009, 03:32 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21