#include <stdio.h>
#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned long long
const uint8_t Table[64] = {
0x21,0x10,0xFE,0x11,0x50,0x7E,0x15,0x88,
0x49,0x32,0x01,0x46,0x20,0x3C,0x15,0x16,
0x24,0x23,0xFD,0x19,0x10,0x09,0xCF,0x4F,
0x18,0x61,0x01,0x21,0x11,0xA6,0xAB,0xF7,
0x13,0x96,0xFB,0x98,0x12,0x3C,0x15,0x15,
0x91,0x12,0x01,0x20,0x17,0x88,0x09,0xCF,
0x22,0x24,0xEF,0x92,0x32,0x15,0x16,0x28,
0x17,0x14,0x01,0x71,0x41,0x2B,0x7E,0x15
};
void Encrypt_ID_Prg(void){
uint8_t i;
uint8_t Encrypt_ID[8] = {0};
uint8_t Device_ID[8] = {0xD8,0xDE,0xDD,0x0A,0x08,0x08,0x2E,0x44};
printf("\nDevice ID:\n");
for(i = 0; i < 8; i++){
if(Device_ID[i] >= 16)
printf("0x%2X, ", Device_ID[i]);
else
printf("0x0%1X, ", Device_ID[i]);
}
printf("\n\nEncrypt Device ID:\n");
for(i = 0; i < 8; i++){
switch(i){
case 0:
Device_ID[i] ^= Table[0];
Device_ID[i] += Table[1];
Device_ID[i] &= Table[2];
Device_ID[i] *= Table[3];
Device_ID[i] ^= Table[4];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
case 1:
Device_ID[i] += Table[8];
Device_ID[i] -= Table[9];
Device_ID[i] = ((Device_ID[i] << Table[10]) & 0xFF);
Device_ID[i] |= Table[11];
Device_ID[i] ^= Table[12];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
case 2:
Device_ID[i] ^= Table[16];
Device_ID[i] += Table[17];
Device_ID[i] &= Table[18];
Device_ID[i] *= Table[19];
Device_ID[i] ^= Table[20];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
case 3:
Device_ID[i] += Table[24];
Device_ID[i] -= Table[25];
Device_ID[i] = ((Device_ID[i] << Table[26]) & 0xFF);
Device_ID[i] |= Table[27];
Device_ID[i] ^= Table[28];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
case 4:
Device_ID[i] ^= Table[32];
Device_ID[i] += Table[33];
Device_ID[i] &= Table[34];
Device_ID[i] *= Table[35];
Device_ID[i] ^= Table[36];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
case 5:
Device_ID[i] += Table[40];
Device_ID[i] -= Table[41];
Device_ID[i] = ((Device_ID[i] << Table[42]) & 0xFF);
Device_ID[i] |= Table[43];
Device_ID[i] ^= Table[44];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
case 6:
Device_ID[i] ^= Table[48];
Device_ID[i] += Table[49];
Device_ID[i] &= Table[50];
Device_ID[i] *= Table[51];
Device_ID[i] ^= Table[52];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
case 7:
Device_ID[i] += Table[56];
Device_ID[i] -= Table[57];
Device_ID[i] = ((Device_ID[i] << Table[58]) & 0xFF);
Device_ID[i] |= Table[59];
Device_ID[i] ^= Table[60];
Encrypt_ID[i] = Device_ID[i];
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
break;
default:
break;
}
}
}
void Decrypt_ID_Prg(void){
uint8_t i;
uint16_t j;
uint8_t Decrypt_ID[8] = {0x00};
uint8_t Encrypt_ID[8] = {0xD8,0xCE,0xAC,0xB2,0x0A,0x39,0x72,0xBE};
printf("\n\nEncrypt Device ID:\n");
for(i = 0; i < 8; i++){
if(Encrypt_ID[i] >= 16)
printf("0x%2X, ", Encrypt_ID[i]);
else
printf("0x0%1X, ", Encrypt_ID[i]);
}
printf("\n\n枚举出的 Device ID:\n");
for(i = 0; i < 8; i++){
switch(i){
case 0:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] ^= Table[0];
Decrypt_ID[i] += Table[1];
Decrypt_ID[i] &= Table[2];
Decrypt_ID[i] *= Table[3];
Decrypt_ID[i] ^= Table[4];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
case 1:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] += Table[8];
Decrypt_ID[i] -= Table[9];
Decrypt_ID[i] = ((Decrypt_ID[i] << Table[10]) & 0xFF);
Decrypt_ID[i] |= Table[11];
Decrypt_ID[i] ^= Table[12];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
case 2:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] ^= Table[16];
Decrypt_ID[i] += Table[17];
Decrypt_ID[i] &= Table[18];
Decrypt_ID[i] *= Table[19];
Decrypt_ID[i] ^= Table[20];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
case 3:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] += Table[24];
Decrypt_ID[i] -= Table[25];
Decrypt_ID[i] = ((Decrypt_ID[i] << Table[26]) & 0xFF);
Decrypt_ID[i] |= Table[27];
Decrypt_ID[i] ^= Table[28];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
case 4:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] ^= Table[32];
Decrypt_ID[i] += Table[33];
Decrypt_ID[i] &= Table[34];
Decrypt_ID[i] *= Table[35];
Decrypt_ID[i] ^= Table[36];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
case 5:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] += Table[40];
Decrypt_ID[i] -= Table[41];
Decrypt_ID[i] = ((Decrypt_ID[i] << Table[42]) & 0xFF);
Decrypt_ID[i] |= Table[43];
Decrypt_ID[i] ^= Table[44];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
case 6:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] ^= Table[48];
Decrypt_ID[i] += Table[49];
Decrypt_ID[i] &= Table[50];
Decrypt_ID[i] *= Table[51];
Decrypt_ID[i] ^= Table[52];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
case 7:
for(j = 0; j < 255; j++){
Decrypt_ID[i] = j;
Decrypt_ID[i] += Table[56];
Decrypt_ID[i] -= Table[57];
Decrypt_ID[i] = ((Decrypt_ID[i] << Table[58]) & 0xFF);
Decrypt_ID[i] |= Table[59];
Decrypt_ID[i] ^= Table[60];
if(Decrypt_ID[i] == Encrypt_ID[i]){
if(j >= 16)
printf("0x%2X, ", j);
else
printf("0x0%1X, ", j);
break;
}
}
break;
default:
break;
}
}
}
int main () {
Encrypt_ID_Prg();
Decrypt_ID_Prg();
return 0;
}