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