汉字加密 解密

文字加密跟解密加密后的文字长度跟解密后的文字長度都是一样
对于要塞入资料库的话会很方便,這支程式是用class写的可以建置成元件来使用
因为可以建置成元件所以就不用可以转成C#語法了...只要建置好VB.net or C#都可以用了

原始码(將档案放在App_Code里)
EverEncode.vb
0 1 Imports Microsoft.VisualBasic
0 2
0 3 Public Class EverEncode
0 4      Function TurnEncode(ByVal FormCode As String) As String
05         Dim EncodeView As String
06         Dim i As Integer
07         Dim jj As Integer
08
09         jj = Len(Trim(FormCode))
10
11         For i = 1 To jj Step 1
12             EncodeView = EncodeView & StringEnDeCodecn(Mid(Trim(FormCode), i, 1))
13         Next i
14         Return EncodeView
15     End Function

16      Function TurnUncode(ByVal FormCode As String) As String
17         Dim i, kk As Integer
18         Dim UnCodeView As String
19         kk = Len(FormCode)
20         For i = 1 To kk Step 1
21             UnCodeView = UnCodeView & StringEnDeCodecn(Mid(Trim(FormCode), i, 1))
22         Next i
23         Return UnCodeView
24
25     End Function

26
27      Private Function StringEnDeCodecn(ByVal strSource As String) As String
28         Dim X As Single
29         Dim CHARNUM As Long
30         Dim RANDOMINTEGER As Integer
31         Dim SINGLECHAR As String
32         Dim strTmp As String
33         Dim i, k As Integer
34
35         For i = 1 To Len(strSource) Step 1
36             SINGLECHAR = Mid(strSource, i, 1)
37             CHARNUM = Asc(SINGLECHAR)
38             CHARNUM = CHARNUM Xor 5
39             strTmp = strTmp & Chr(CHARNUM)
40         Next i
41
42         If strTmp = "?" Then
43             strTmp = ""
44             For k = 1 To Len(strSource) Step 1
45                 SINGLECHAR = Mid(strSource, k, 1)
46                 CHARNUM = Asc(SINGLECHAR)
47                 strTmp = strTmp & Chr(CHARNUM)
48             Next k
49         End If
50
51         Return strTmp
52         Exit Function
53
54     End Function

55 End Class


使用C#來测试加解密文字

0 1      protected void Page_Load( object sender, EventArgs e)
0 2      {
03         EverEncode code = new EverEncode();
04
05         //puma會加密成→uphd
06         Response.Write(code.TurnEncode("puma")); Response.Write("<br />");
07
08         //uphd會解密成→puma
09         Response.Write(code.TurnUncode("uphd"));
10     }

你可能感兴趣的:(加密)