先引用midea0978兄的原文,希望midea0978兄不要介意^_^
最近碰到这样一个算法,过程并不复杂,但是思考了很久也没有找到对应的逆运算算法,这里发布出来,希望有高人能够提供思路,
如果有具体的代码实现就最好了。
实现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}
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}
上面是原文,我对midea0978的《.net平台的RSA实现以及与Delphi之间的互操作性》非常感兴趣,看到他求这算法的分析,就试着看了。一看下来,就是20多小时……
后面我慢慢把分析过程发上来。