VC string Encryption

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.