本帖最后由 moocher 于 2022-5-21 19:07 编辑
[C] 纯文本查看 复制代码
#include <stdio.h>
#define MAX_DATA_LEN 12
char OriginData[MAX_DATA_LEN]= {'2','7','9','4','2','2','9','4','2','2','9','4'};//输入279422942294,输出32FK156637FK
char calcuData[MAX_DATA_LEN]; //calculated data
int DataTransfer(char *dataIn, char *dataOut)
{
int i = 0;
char a1 = dataIn[0];
char b1 = dataIn[11];
char compleCode; //c1, complement code
int asciiCode;
for(i=0; i<MAX_DATA_LEN; i++)
{
compleCode = 0xff - dataIn[i];
asciiCode = b1 * a1 * (i+1) * 12 + compleCode;
asciiCode = asciiCode & 0xff;
//printf("%02x,compleCode;\n", compleCode);
// printf("%02x,asciiCode;\n", asciiCode);
if('0' == asciiCode)
{
dataOut[i] = '1';
}
else if('O' == asciiCode)
{
dataOut[i] = '2';
}
else if('o' == asciiCode)
{
dataOut[i] = '3';
}
else if(('1' <= asciiCode) && (asciiCode <= '9'))
{
dataOut[i] = asciiCode;
}
else if(('A' <= asciiCode) && (asciiCode <= 'Z'))
{
dataOut[i] = asciiCode;
}
else if(('a' <= asciiCode) && (asciiCode <= 'z'))
{
dataOut[i] = asciiCode + 'A' - 'a';
}
else
{
dataOut[i] = (asciiCode % 9) + 1 + '0';
}
}
return 0;
}
int main(void)
{
DataTransfer(OriginData, calcuData);
printf(calcuData);
return 0;
}
|