How does WeChat Mini Programs use the CPP source code to convert this algorithm function into JS executable code?

I want to make a calculator in WeChat Mini Programs. There is only an input box and an output box. The user enters a numeric password (6-12 digits) into the input box and then clicks the calculation button. The system will use this password plus the current time value as a parameter, and use the TEA algorithm to calculate a new password, which is valid for 15 minutes. The following is the written C code, I want to encapsulate it into DLL and then call it, but WeChat Mini Programs is on Wechat"s server, DLL will not be uploaded and used casually! Which warrior can convert this function into code that can be written directly in WeChat Mini Programs and give it all away!

test.c source code is as follows:

//========================================TEA========================================================================================================================
-sharpdefine mSecDataTempPd    0x5aa555aa
const DWORD coSecDataTempPd = (mSecDataTempPd ^ 0x9e3779b9);
const DWORD coKeyTempPd[] = {0x126f2e1b,0xd1ef3da9,0xa7469115,0x6d83ea82};

/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pData_fGet1TimePd    6-1212123456{0x01,0x02,0x03,0x04,0x05,0x06,0xff,0xff,0xff,0xff,0xff,0xff}
dTime_fGet1TimePd    197011000long
pPd_fGet1TimePd    8
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
void fGet1TimePd(BYTE* pData_fGet1TimePd,DWORD dTime_fGet1TimePd,BYTE* pPd_fGet1TimePd)
{
DWORD dData_fGet1TimePd[2];
BYTE* pTemp_fGet1TimePd = (BYTE*)dData_fGet1TimePd;
BYTE bTemp_fGet1TimePd;

dTime_fGet1TimePd /= _TempPdCyc_;
for(bTemp_fGet1TimePd = 0;bTemp_fGet1TimePd < 8;bTemp_fGet1TimePd PP)
{
if(bTemp_fGet1TimePd < 6)
{
pTemp_fGet1TimePd[bTemp_fGet1TimePd] = ((pData_fGet1TimePd[bTemp_fGet1TimePd * 2] << 4) & 0xf0) | (pData_fGet1TimePd[bTemp_fGet1TimePd * 2 + 1] & 0x0f);
}
else
{
pTemp_fGet1TimePd[bTemp_fGet1TimePd] = 0;
}

if(bTemp_fGet1TimePd > 3)
{
pTemp_fGet1TimePd[bTemp_fGet1TimePd] ^= (dTime_fGet1TimePd >> ((7 - bTemp_fGet1TimePd) * 8));
}
}
fEncryptTea(&dData_fGet1TimePd[0],&dData_fGet1TimePd[1]);

for(bTemp_fGet1TimePd = 0;bTemp_fGet1TimePd < 8;bTemp_fGet1TimePd PP)
{
pPd_fGet1TimePd[bTemp_fGet1TimePd] = (((pTemp_fGet1TimePd[bTemp_fGet1TimePd] >> 4) & 0x0f) ^ (pTemp_fGet1TimePd[bTemp_fGet1TimePd] & 0x0f)) % 10;
}
}

void fEncryptTea(DWORD *fData1_fEncryptTea,DWORD *fData2_fEncryptTea)
{
DWORD dTemp1_fEncryptTea = *fData1_fEncryptTea;
DWORD dTemp2_fEncryptTea = *fData2_fEncryptTea;
DWORD dSum_fEncryptTea = 0;
DWORD dDelta_fEncryptTea = coSecDataTempPd ^ mSecDataTempPd;
BYTE bTemp_fEncryptTea;

for (bTemp_fEncryptTea = 0;bTemp_fEncryptTea < 8;bTemp_fEncryptTea PP)    //8()
{
dSum_fEncryptTea += dDelta_fEncryptTea;
dTemp1_fEncryptTea += ((dTemp2_fEncryptTea << 4) + coKeyTempPd[0]) ^ (dTemp2_fEncryptTea + dSum_fEncryptTea) ^ ((dTemp2_fEncryptTea >> 5) + coKeyTempPd[1]);
dTemp2_fEncryptTea += ((dTemp1_fEncryptTea << 4) + coKeyTempPd[2]) ^ (dTemp1_fEncryptTea + dSum_fEncryptTea) ^ ((dTemp1_fEncryptTea >> 5) + coKeyTempPd[3]);
}

fData1_fEncryptTea[0] = dTemp1_fEncryptTea;
fData2_fEncryptTea[0] = dTemp2_fEncryptTea;
}

test.h:
-sharpifndef _tea_h_
-sharpdefine _tea_h_

-sharpdefine _TempPdCyc_    (15 * 60L)    //15x60900s15

void fEncryptTea(DWORD *fData1_fEncryptTea,DWORD *fData2_fEncryptTea);
void fDecryptTea(DWORD *fData1_fDecryptTea,DWORD *fData2_fDecryptTea);


-sharpendif

above is all the calculation algorithm code. Please convert the hero to a language that can be used in WeChat Mini Programs, online, etc.

Mar.03,2022

No one can? The same questions will be solved!


https://github.com/kripken/em.


There is a loop-plus logic in the

code. Does it use DWORD-type overflows? Number in JS is of double type and has no overflow effect. So it needs to be tested.

-Update-

added bitwise and 0xffffffff to make number in js behave like DWORD. In addition, isn't the dDelta_fEncryptTea in the source code 0x9e3779b9? why should it be calculated every time?


var p = new Uint8Array([0x01,0x02,0x03,0x04,0x05,0x06,0xff,0xff,0xff,0xff,0xff,0xff]);
console.log(getTempPasswd(p, new Date()));
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38097-2c0c3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38097-2c0c3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?