2 zp19810828 csnd zp19810828_csnd 于 2015.06.03 16:52 提问

求算法实现或代码修改 5C

算法说明

图片说明

图片说明

图片说明

正确的运算结果:

例1:S1、S2、S3为E0、6E、E3,F1-F5为4D、61、7A、64、41经过算法后返回R1、R2、R3为:74、4C、49

例2:S1、S2、S3为5B、68、43,F1-F5为4D、61、7A、64、41经过算法后返回R1、R2、R3为:CA、B3、E1

例1:S1、S2、S3为,3E、B5、C3,F1-F5为4E、53、59、4E、53经过算法后返回R1、R2、R3为:93、EB、E1

# 我的代码:

#define TEYES_ABS67_MASK 0x4D617A6441

void Security ( void )

{

unsigned char SecurityData[3];

unsigned char SecurityKey[3];

unsigned long SecurityA,SecurityB,SecurityC,SecurityTemp;

uint64_t SecurityCB;

unsigned char i,chrTemp1,chrTemp2;

//SecurityData[3]:Data from ABS.

//SecurityKey[3]:Result.

//Calculation.

//Step 1

SecurityData[]={0xE3,0x6E,0xE0};

SecurityTemp = SecurityData[2];

SecurityTemp = SecurityTemp * 256 + SecurityData[1];

SecurityTemp = SecurityTemp * 256 + SecurityData[0];

SecurityCB = TEYES_ABS67_MASK;

SecurityCB = SecurityCB * 0x01000000;

SecurityCB = SecurityCB + SecurityTemp;

//Setp 2

SecurityC = 0x00C541A9;

//Setp 3

for (i=0;i<64;i++)

{

SecurityA = SecurityC;

if (SecurityCB & 1) chrTemp1 = 1;

else chrTemp1 = 0;

if (SecurityA & 1) chrTemp2 = 1;

else chrTemp2 = 0;

chrTemp1 = chrTemp1 ^ chrTemp2;

SecurityB = SecurityA >> 1;

if (chrTemp1)

{

SecurityB = SecurityB | 0x00800000;

SecurityTemp = 0x109028;

}

else SecurityTemp = 0;

SecurityTemp = SecurityTemp ^ SecurityB;

SecurityTemp = SecurityTemp & 0x109028;

SecurityC = SecurityB;

SecurityC = SecurityC & (~0x109028);

SecurityC = SecurityC + SecurityTemp;

}

//Step 4

SecurityKey[0] = (unsigned char)((SecurityC >> 4) % 256);

SecurityKey[1] = (unsigned char)((SecurityC >> 12) % 16);

SecurityKey[1] = SecurityKey[1] * 16 + (unsigned char)((SecurityC >> 20) % 16);

SecurityKey[2] = (unsigned char)(SecurityC % 16);

SecurityKey[2] = SecurityKey[2] * 16 + (unsigned char)((SecurityC >> 16) % 16);

}

int main(void)

{

Security();

}

Csdn user default icon
上传中...
上传图片
插入图片