C # ways to encrypt letters or numbers into letters

Source: Internet
Author: User
Tags decrypt

The example in this article describes how C # encrypts letters or numbers into letters. Share to everyone for your reference. The implementation method is as follows:


The code is as follows:

public class MD5

{

Static List<keyvaluepair<char, char>> mappinglist;

#region Encrypt public static string Encrypt (String str)

<summary>

Encryption

</summary>

<param name= "str" > string to encrypt </param>

<returns> string that returns the result </returns>

public static string Encrypt (String str)

{

Mappinglist = new List<keyvaluepair<char, char>> ();

for (char C = ' 0 '; c <= ' 9 '; C + +)

Mappinglist.add (New Keyvaluepair<char, Char> (c, (char) (c – ' 0 ' + ' a '));

for (char c = ' a '; C <= ' F '; C + +)

Mappinglist.add (New Keyvaluepair<char, Char> (c, (char) (c – ' a ' + ' u '));

return Encoding.ASCII.GetBytes (str)

. Select ((b, i) = = (b ^ ((byte) (0xa0 + i)). ToString ("X2"))

. Aggregate ("", (s, c) = + S + C)

. ToCharArray (). Select (c = mappinglist.first (kv = kv). Key = = c). Value)

. Aggregate ("", (s, c) = + S + c);

}

#endregion

#region Decrypt public static string Decrypt (String str)

<summary>

Decrypt

</summary>

<param name= "str" > decrypted string </param>

<returns> return result string </returns>

public static string Decrypt (String str)

{

string base16 = str. ToCharArray ()

. Select (c = mappinglist.first (kv = kv). Value = = c). Key)

. Aggregate ("", (s, c) = + S + c);

Return Encoding.ASCII.GetString (New Byte[base16. LENGTH/2])

. Select ((b, i) = = (byte) (Convert.tobyte (BASE16). Substring (i * 2, 2), +) ^ ((byte) (0xa0 + i))). ToArray ());

}

#endregion

}

I hope this article is helpful to everyone's C # programming.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # ways to encrypt letters or numbers into letters

This address: http://www.paobuke.com/develop/c-develop/pbk23120.html






Related content method of JSON serialization in C # to remove null values C # implements a method of converting a collection to JSON-formatted data C # Implementation of the ListView group Shrink extension method Ó? C#?? Í??? ±£′?? Áoracle BLOBX???? Dμ?? ¨
C # Methods for the statistics of TCP connection information C # file and byte stream conversion methods C # Methods for manipulating the Windows Registry C # implements how to get the number of elements in an enumeration

C # ways to encrypt letters or numbers into letters

Related Article

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.