OK. What I found out:
Code: Select all
class CSecondPwdRandom {
public:
CSecondPwdRandom(int dwSeed) {
m_holdrand = dwSeed;
m_mulfactor = 13464;
m_addfactor = 8917556;
};
void Randomize(char *cStr, int dwStrLen) {
if (dwStrLen >= 1) {
int k = 2;
for (int pos = 1; pos <= dwStrLen; pos++) {
m_holdrand = m_addfactor + m_mulfactor * m_holdrand;
int replace_pos = pRandom->m_holdrand % k;
if (pos != replace_pos) {
swap (cStr[pos], cStr[replace_pos]);
};
k++;
};
};
};
int m_holdrand;
int m_mulfactor;
int m_addfactor;
};
bool CSecondPasswdMgr::RandNumSeq(char *out_szRet, int in_nOutStrSize, unsigned long in_dwSeed, char const *in_pbyKeyPadIdx, int in_nIdxSize) {
if (! in_dwSeed)
return false;
if (! in_pbyKeyPadIdx)
return false;
char szKeyPad[10];
memcpy_s(szKeyPad, 10, "0123456789", sizeof(szKeyPad));
CSecondPwdRandom *cPwdRandom = new CSecondPwdRandom(in_dwSeed);
cPwdRandom->Randomize(&szKeyPad, sizeof(szKeyPad));
for (int i = 0; i < 4; i++) {
out_szRet[i] = szKeyPad[in_pbyKeyPadIdx[i]];
};
out_szRet[4] = 0;
return true;
};
I could been not too accurate about CSecondPwdRandom::Randomize function. But you can get the general idea on how things work.
The original code is actually a std::random_shuffle with custom "my_random" function provided. But because Optimizer is enabled, it looks RLY ugly inside.
the "my_random" function should look like this:
Code: Select all
int my_random(CSecondPwdRandom *cSPwdRandom) {
cSPwdRandom->m_holdrand = cSPwdRandom->m_addfactor + cSPwdRandom->m_mulfactor * cSPwdRandom->m_holdrand;
return pRandom->m_holdrand;
}