BOOL CTVMSKEncrypt::Decrypt(CString strToDecrypt,CString strDecryptParam,CString &strDecryptResult)
{
strDecryptResult.Empty(); int nLen =strToDecrypt.GetLength();
int nPLen =strDecryptParam.GetLength();
if(strToDecrypt.GetLength() != 100)
{
return FALSE;
} int nRealPassLen = strToDecrypt.GetAt(60) - 65;
int nRealParaLen = strToDecrypt.GetAt(61) - 65; if(nRealParaLen != nPLen)
{
return FALSE;
} for(int i=0; i<nPLen;i++)
{
if(strToDecrypt[i+62]-1 != strDecryptParam[i])
{
return FALSE;
} if(::IsDBCSLeadByte(strDecryptParam[i]))
{
i++; if(strToDecrypt[i+62] != strDecryptParam[i])
{
return FALSE;
}
}
} for(i=0;i<nRealPassLen;i++)
{
char ch = strToDecrypt.GetAt(i);
char ch1 = strDecryptParam.GetAt(i%nPLen);
int nBit = i%8;
int nMask = 1 << nBit;
int nRes = ch1&nMask;
if(nRes > 0)
{
ch -= 2;
}
else
{
ch -= 1;
} strDecryptResult.Insert(i,ch); if(::IsDBCSLeadByte(ch))
{
i++;
strDecryptResult.Insert(i,strToDecrypt.GetAt(i));
}
} return TRUE;
}
{
strDecryptResult.Empty(); int nLen =strToDecrypt.GetLength();
int nPLen =strDecryptParam.GetLength();
if(strToDecrypt.GetLength() != 100)
{
return FALSE;
} int nRealPassLen = strToDecrypt.GetAt(60) - 65;
int nRealParaLen = strToDecrypt.GetAt(61) - 65; if(nRealParaLen != nPLen)
{
return FALSE;
} for(int i=0; i<nPLen;i++)
{
if(strToDecrypt[i+62]-1 != strDecryptParam[i])
{
return FALSE;
} if(::IsDBCSLeadByte(strDecryptParam[i]))
{
i++; if(strToDecrypt[i+62] != strDecryptParam[i])
{
return FALSE;
}
}
} for(i=0;i<nRealPassLen;i++)
{
char ch = strToDecrypt.GetAt(i);
char ch1 = strDecryptParam.GetAt(i%nPLen);
int nBit = i%8;
int nMask = 1 << nBit;
int nRes = ch1&nMask;
if(nRes > 0)
{
ch -= 2;
}
else
{
ch -= 1;
} strDecryptResult.Insert(i,ch); if(::IsDBCSLeadByte(ch))
{
i++;
strDecryptResult.Insert(i,strToDecrypt.GetAt(i));
}
} return TRUE;
}
USES_CONVERSION;
_com_util::ConvertStringToBSTR()
BOOL CTVMSKEncrypt::Decrypt(BSTR bstrToDecrypt,BSTR bstrDecryptParam,BSTR &bstrDecryptResult)
{
USES_CONVERSION;
CString strDecryptResult;
CString strToDecrypt = _com_util::ConvertBSTRToString(bstrToDecrypt);
CString strDecryptParam= _com_util::ConvertBSTRToString(bstrDecryptParam);
....... bstrDecryptResult = _com_util::ConvertStringToBSTR(strDecryptResult);}