Parse the application of Asp.net, C # pure digital encryption and decryption string

Source: Internet
Author: User

Further to the previous article: Asp.net, C # detailed instructions on the use of encryption and decryption strings, some netizens asked:

That is to say, the encrypted data is no longer: N8lAaHMFtSAQgaf3 + RUFng =

You want encryptedString to be "120387789370480938409832840923492384028934 ...";

Of course, I randomly typed the above numbers.

How can we implement pure numbers ??

The idea is simple. You only need to convert the character into an Ascll code. For example, a: 97, =: 61;

Then encryptedString can be changed to 97 81 61 33 44 55 ...;

However, if they are combined, they become 978161334455.

Question: How do I know that 97 is a, not 9 or 7?

If you know that the computer is a binary representation, you can think that we can change 97 to the 0, 1 form.

The above number can be changed to 0001 0011 011 111 001.

OK, we still have 2, 3, 4, 5, 6, 7, 8, 9, not used, so we can use any character to separate.

For example, convert the preceding number to 0001 2 0011 2 011 2 111 2 001

Of course, the above Code can be completed, but there are still 3, 4, 5, 6, 7, 8, and 9 which are wasted,

So here we should not choose 2 hexadecimal, we 'd better choose 9 hexadecimal. What ?? 9 hexadecimal?

Right, 9: 0, 1, 2, 4, 5, 6, 7, 8, 10. 10 indicates 9, and 9 is used as the separator;

Unfortunately, the C # code does not support 9-in-order to facilitate the selection of 8-in-order.

The Code is as follows:

Copy codeThe Code is as follows: // <summary>
/// Convert a string to a numeric string
/// </Summary>
/// <Param name = "value"> </param>
/// <Returns> </returns>
Private static string ConvertStringToNumbers (string value)
{
StringBuilder sb = new StringBuilder ();

Foreach (char c in value)
{
Int cascel = (int) c;
Sb. Append (Convert. ToString (c, 8) + "9 ");
}

Return sb. ToString ();
}

String encryptedNumberString = ConvertStringToNumbers (encryptedString );

EncryptedNumberString = 11697091549101914191109115910691649123.

91019121914791419146963953912291259106915691479759759

Well, the strings have been successfully separated, and the rest is to re-extract the characters from the string consisting of the numbers.

The Code is as follows:

Copy codeThe Code is as follows: // <summary>
/// Convert a numeric string to a normal character string
/// </Summary>
/// <Param name = "value"> </param>
/// <Returns> </returns>
Private static string ConvertNumbersToString (string value)
{
String [] splitInt = value. Split (new char [] {'9'}, StringSplitOptions. RemoveEmptyEntries );

Var splitChars = splitInt. Select (s => Convert. ToChar (
Convert. ToInt32 (s, 8)
). ToString ());

Return string. Join ("", splitChars );
}

The result is as follows:

The rest depends on the readers themselves...

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.