XOR with MAC and windows registry

Posted on 2006-05-17
Last Modified: 2010-04-24
void outputMAC(unsigned char MAC[])
   printf("Your MAC Address Is: %02X-%02X-%02X-%02X-%02X-%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);

// Read Mac
      IP_ADAPTER_INFO AdapterInfo[2];
      DWORD dwBufSize = sizeof(AdapterInfo);
      DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufSize);
      PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
        pAdapterInfo = pAdapterInfo->Next;
    // end read mac
//read windows registry
       if( RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\mycompany\\mysoft",0,KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
                RegQueryValueEx( keyHandle, "ProgramHasRunBefore", NULL, &Type, (LPBYTE)rgValue,&size1);


     return CKBR_OK;

HI I want to perform the following tasks:

1  Read the local computer MAC address
2  Read a windows registry
3. Perform the XOR operation of 1 and 2 and get the final 3 digits


MAC: 0004758226EA
reg. 164D04A6278D

output: 164971240167
First 9 digits= 164971240
final 3 digits = 167
now in my code, i can read teh MAC address properly and I can read teh registry as well

but I don't know how to modify my routine so that we can achieve the 3 operations.

anyone can help?
Question by:goretti
    LVL 11

    Expert Comment

    you could do something like:

    int XorValue = MAC ^ Reg;

    XorValue &= 0x0000FFF

    the & operator will preserve the values of the last 3 bytes and set the rest to 0

    Author Comment

    the concept is ok
    but how can I modify the code based on my example?

    Author Comment

    The problem  now is MAC[0] store 2 digits and rgValue[0] store 1 digit

    i want to form a string from MAC and so do the XOR one by one with rgValue
    LVL 49

    Accepted Solution

    The MAC address is 6 bytes long.  In the first line, you convert it to a string of hex digits in a normal manner.

    To XOR some OTHER 6-byte value against the MAC, first prepare that other value (let's say that is the key) as an array of 6 bytes, anKey[0] through anKey[5].

    Now loop through the six bytes, outputting to a third array, anResult[0]...[5]

    BYTE anKey[6];   // fill with binary data that was stored in the registry
    BYTE anMAC[6];   // fill with binary data from IP_ADAPTER_INFO.Address
    BYTE anResult[6];

    for (int j=0; j<6; j++ ) {
           anResult[j] = anMAC[j] ^ anKey[j];

    Now you can convert the results value to a string and grab the final three characters...

       char szEncrypted[13];
       sprintf(szEncrypted, "%02X%02X%02X%02X%02X%02X",
                   anResult[0], anResult[1], anResult[2], anResult[3], anResult[4], anResult[5]

       char szfinalThreeChars[4];
       strcpy( szfinalThreeChars, &szEncrypted[9] );
       printf("The final 3 chars after XOR are: %s\r\n", szfinalThreeChars );

    -- Dan
    LVL 8

    Expert Comment

    This is also answered in


    sprintf(TheResult, "%01X%02X", (MAC[4] & 0xF)^rgValue[9], MAC[5]^(rgValue[10] << 4 + rgValue[11]));

    (Not tested, BTW)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now