Files
checker_host/elec/JQ_PSDGenerate.cpp

87 lines
2.2 KiB
C++
Raw Normal View History

#include "JQ_PSDGenerate.h"
/********************************************************************************************************************
* BCD码 *
********************************************************************************************************************/
static uint32_t GetSpecialCodeIndex(uint8_t ucSpecialCode)
{
if (ucSpecialCode >= '0' && ucSpecialCode <= '9')
{
return ucSpecialCode - 0x30;
}
else if (ucSpecialCode >= 'A' && ucSpecialCode <= 'Z')
{
return ucSpecialCode - 'A' + 10;
}
else if (ucSpecialCode >= 'a' && ucSpecialCode <= 'z')
{
return ucSpecialCode - 'a' + 36;
}
else
return 63;
}
static uint32_t GetiDateInfo(uint8_t *ucpDate)
{
uint8_t ucMonth = ucpDate[0]*10 + ucpDate[1];
uint8_t ucDay = ucpDate[2]*10 + ucpDate[3];
return ucMonth << 5 | ucDay;
}
//public static string GetPasswordByShellCode(string shellcode)
//{
// string ssp = shellcode.Substring(7, 1);
// string sdate = shellcode.Substring(3, 4);
// string sindex = shellcode.Substring(8, 5);
// UInt32 u32BCD = (UInt32)(((GetiDateInfo(sdate) & 0x1FF) << 23) |
// ((GetSpecialCodeIndex(ssp) & 0x3F) << 17) |
// (GetiIndex(sindex) & 0x1FFFF));
// return U32tohexstr(u32BCD);
//}
uint8_t JQ_GetPasswordByUidCode(const uint8_t *uidcode,uint8_t* psd)
{
uint8_t ucSpecialCode = 0;
uint8_t usaDate[4] = {0};
uint32_t ulIndex = 0;
uint32_t ulBCDPsd = 0;
uint8_t i=0;
//581900230A12345
ucSpecialCode = uidcode[9];
for(i=5;i<9;i++)
usaDate[i-5] = uidcode[i]-0x30;
for(i=10;i<15;i++)
{
ulIndex *= 10;
ulIndex += (uidcode[i]-0x30);
}
ulBCDPsd = (GetiDateInfo(usaDate) & 0x1FF) << 23 |
(GetSpecialCodeIndex(ucSpecialCode) & 0x3F) << 17 |
ulIndex & 0x1FFFF;
// psd[0] = (ulBCDPsd&0xFF000000)>>24;
// psd[1] = (ulBCDPsd&0x00FF0000)>>16;
// psd[2] = (ulBCDPsd&0x0000FF00)>>8;
// psd[3] = ulBCDPsd&0x000000FF;
// 反序
psd[3] = (ulBCDPsd&0xFF000000)>>24;
psd[2] = (ulBCDPsd&0x00FF0000)>>16;
psd[1] = (ulBCDPsd&0x0000FF00)>>8;
psd[0] = ulBCDPsd&0x000000FF;
return 0;
}