XOR with MAC and windows registry

Posted on 2006-05-17
Medium Priority
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

ID: 16698514
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

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

Author Comment

ID: 16705784
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

DanRollins earned 200 total points
ID: 16716697
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

Expert Comment

by:Knut Hunstad
ID: 16718100
This is also answered in http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VisualC_PLUS_PLUS_DOT_NET/Q_21854805.html:


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

(Not tested, BTW)

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses

839 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