code_en_de.cs
上传用户:chizxy
上传日期:2014-11-29
资源大小:407k
文件大小:2k
- using System;
- using System.Text;
- namespace conn
- {
-
- public class code_en_de
- {
- private static char[] key = "yA36zA48dEhfrvghGRg57h5UlDv3".ToCharArray();
-
- public static string Decode(string x)
- {
- System.Text.StringBuilder sb = new System.Text.StringBuilder();
- char[] ca = x.ToCharArray();
- for (int i = 0; i < (ca.Length - 2); i += 2)
- {
- string s1 = "" + ca[i + 2] + ca[i + 3];
- string s2 = "" + System.Convert.ToString((byte) key[(i / 2) % 13], 16);
- string s3 = "" + ca[i] + ca[i + 1];
- int m = (System.Convert.ToInt32(s1, 16) ^ System.Convert.ToInt32(s2, 16)) - System.Convert.ToInt32(s3, 16);
- if (m < 0)
- {
- m += 255;
- }
- sb.Append((char) ((short) m));
- }
- return sb.ToString();
- }
- public static string Encode(string x)
- {
- char[] ca = x.ToCharArray();
- int k = new System.Random().Next(255);
- System.Text.StringBuilder sb = null;
- if (k > 15)
- {
- sb = new System.Text.StringBuilder("" + System.Convert.ToString(k, 16));
- }
- else
- {
- sb = new System.Text.StringBuilder("0" + System.Convert.ToString(k, 16));
- }
- int m = System.Convert.ToInt32(sb.ToString(), 16);
- for (int i = 0; i < ca.Length; i++)
- {
- if ((ca[i] + m) > 255)
- {
- m = ((ca[i] + m) - 255) ^ key[i % 13];
- }
- else
- {
- m = (ca[i] + m) ^ key[i % 13];
- }
- if (m > 15)
- {
- sb.Append(System.Convert.ToString(m, 16));
- }
- else
- {
- sb.Append("0" + System.Convert.ToString(m, 16));
- }
- }
- return sb.ToString().ToUpper();
- }
- }
- }