Encryption
Cstring cmainframe: encodestr (lpctstr lpszsrc)
{
Cstring strdest = "";
Int I, J, K;
Cstring S1, S3 = lpszsrc ;;
Int nlength = s3.getlength ();
K = 4-nlength % 4; // The number of digits behind the multiples of 4
For (I = 0; I <(k-1); I ++)
S3 + = ('Z'-k-I * 3 );
S1.format ("% d", k );
S3 + = S1;
For (I = 0; I <(nlength + k); I + = 4)
{
S1 = s3.mid (I, 4 );
For (j = 3; j> = 0; j --)
{
Strdest + = S1 [J]-9;
}
}
Return strdest;
}
Decryption
Cstring cmainframe: decodestr (lpctstr lpszsrc)
{
Cstring strdest = "";
Int I, J;
Cstring S1, S3 = lpszsrc;
Int nlength = s3.getlength ();
For (I = 0; I <nlength; I + = 4)
{
S1 = s3.mid (I, 4 );
For (j = 3; j> = 0; j --)
{
Strdest + = S1 [J] + 9;
}
}
J = atoi (strdest. Right (1 ));
If (j> 0)
Strdest. Delete (nlength-J, J );
Return strdest;
}
Now, when there is zero in the input string, it won't work, for example, 1023 encryption, but I cannot insert it into the database after encryption, as long as the input string does not contain zero, you can, ask experts, let's take a look at how to solve this problem. Thank you.
Http://topic.csdn.net/u/20081223/13/5cfa4fa8-a201-4669-be4d-f3d4ca1744a2.html