1
/// <summary>
2
/// 三位64位加密
3
/// </summary>
4
/// <param name="name">原字符</param>
5
/// <param name="key">密鈅</param>
6
/// <param name="len">原字符最大長度</param>
7
/// <param name="flx">加密復雜系數大於122不等于64的倍數</param>
8
/// <returns>返回加密文</returns>
9
private string GetBuHash(string name,string key,int len,int flx)
10
{
11
//string key="OovM=V5frFWe+w1aEANnjR6sJS2iIbBxZz9QKgqDU43pPLlYycC0uThGHtdX8km7";
12
Random rand;
13
string buinfo="";
14
int k,j,l;
15
if(name==null || name.Length<1|| name.Length>len) return "";
16
int rndid=262144/flx;
17
for(int i=0;i<len;i++)
18
{
19
rand=new Random((int)((i+1)*DateTime.Now.Ticks)%Int32.MaxValue);
20
j=rand.Next(rndid);
21
22
k=j*flx;
23
if(i<name.Length)
24
l=(int)name[i];
25
else
26
l=rand.Next(10)+48;
27
k+=l;
28
buinfo+=convert(k,64,key);
29
30
}
31
return buinfo;
32
33
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

以上加密方法尚未改進,適合字母.
以下是解密函數.
1
public static string RgetBuStr(string pass,string key,int flx)
2
{
3
if(pass.Length>0 && pass.Length%3!=0) return "";
4
int ind,total=0,k,j=0;
5
char[] ch=new char[pass.Length/3];
6
for(int i=0;i<pass.Length/3;i++)
7
{
8
ind=key.IndexOf(pass[i*3]);
9
if(ind>-1) total+=ind*64*64;
10
ind=key.IndexOf(pass[i*3+1]);
11
if(ind>-1) total+=ind*64;
12
ind=key.IndexOf(pass[i*3+2]);
13
if(ind>-1) total+=ind;
14
k=total%flx;
15
ch[i]=(char)k;
16
if(k<58) j++;
17
total=0;
18
}
19
return new String(ch);//返回解密原文.
20
//return new String(ch,0,pass.Length/3-j);返回原文.
21
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

以下是產生64位密碼(由64個不同字符,類似base64,故密碼中的字符不重復)的方法:
1
private string GetKey()
2
{
3
char dd;
4
int i;
5
Random rand;
6
System.Text.StringBuilder retstr=new StringBuilder("");
7
for(int j=0;j<64;j++)
8
{
9
rand=new Random((int)((j+1)*DateTime.Now.Ticks)%Int32.MaxValue);
10
i=rand.Next(retstr.Length+1)+1;
11
if(j<10)
12
{
13
dd=(char)(j+48);
14
}
15
else if(j>=10 && j<=35)
16
{
17
dd=(char)(j+55);
18
}
19
else if(j==62)
20
dd='+';
21
else if(j==63)
22
dd='=';
23
else
24
dd=(char)(j+61);
25
if(retstr.Length<=0)
26
retstr.Append(dd);
27
else if(i>retstr.Length)
28
retstr.Append(dd);
29
else
30
retstr.Insert(i-1,dd);
31
}
32
return retstr.ToString();
33
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

歡迎大家指正其中的不足.
已經有進一步改進方法.如加入校驗碼.
之后再奉上.