一個C#演算法分析求解
來源:互聯網
上載者:User
最近碰到這樣一個演算法,過程並不複雜,但是思考了很久也沒有找到對應的逆運算演算法,這裡發布出來,希望有高人能夠提供思路,
如果有具體的代碼實現就最好了。
實現public static String ReCalc(byte[] buffer1)方法,保證
if(text==text1) Console.WriteLine("ok");
就可以了 1String text="5UYTSHZ0PL4Q3RB26FD";
2byte[] mydata=new byte[12];
3calc_1(text,mydata);
4String text1=ReCalc(data);
5if(text==text1) Console.WriteLine("ok");
6
7//實現下面方法,滿足上麵條件
8public static String ReCalc(byte[] buffer1){
9 return "";
10}
11
12public static void Calc(string text1, byte[] buffer1)
13{
14 ushort num1 = 11;
15 uint num2 = 0;
16 uint num3 = 0;
17 int num4 = 0;
18 while ((num2 < buffer1.Length) && (num3 < 90))
19 {
20 uint num5 = CalcNum(text1[num4++]);
21 if (num5 == 0xffff)
22 {
23 throw new Exception("Error");
24 }
25 num5 = num5 << (num1 & 0x1f);
26 buffer1[num2] = Convert.ToByte(buffer1[num2] | ((num5 & 0xff00) >> 8));
27 buffer1[num2 + 1] = Convert.ToByte(buffer1[num2 + 1] | (num5 & 0xff));
28 if (num1 < 8)
29 {
30 num1 += 3;
31 num2++;
32 }
33 else
34 {
35 num1 -= 5;
36 }
37 num3 += 5;
38 }
39}
40
41public static uint CalcNum(char c){
42 String data="6HC3QBW9K2FUL8XJ4P0TN5DEAZ1YR7VG";
43 for(int i=0;i<data.Length;i++){
44 if(data[i]==c) return (uint)i;
45 }
46 return 0xffff;
47}