<%
'asp 的DES加密文件(V6bbs修正版)
Public Function bit2byte(s)
Dim s2
Dim x
Dim i, k
Dim ilen
ilen = Len(s)
Dim B()
Dim s1()
ReDim s1(ilen)
ReDim B(ilen * 8)
s2 = ""
For i = 1 To ilen
x = Mid(s, i, 1)
s1(i) = Asc(x)
If s1(i) And &H80 Then
B(1 + 8 * (i - 1)) = 1
Else
B(1 + 8 * (i - 1)) = 0
End If
If s1(i) And &H40 Then
B(2 + 8 * (i - 1)) = 1
Else
B(2 + 8 * (i - 1)) = 0
End If
If s1(i) And &H20 Then
B(3 + 8 * (i - 1)) = 1
Else
B(3 + 8 * (i - 1)) = 0
End If
If s1(i) And &H10 Then
B(4 + 8 * (i - 1)) = 1
Else
B(4 + 8 * (i - 1)) = 0
End If
If s1(i) And &H8 Then
B(5 + 8 * (i - 1)) = 1
Else
B(5 + 8 * (i - 1)) = 0
End If
If s1(i) And &H4 Then
B(6 + 8 * (i - 1)) = 1
Else
B(6 + 8 * (i - 1)) = 0
End If
If s1(i) And &H2 Then
B(7 + 8 * (i - 1)) = 1
Else
B(7 + 8 * (i - 1)) = 0
End If
If s1(i) And "1" Then
B(8 + 8 * (i - 1)) = 1
Else
B(8 + 8 * (i - 1)) = 0
End If
Next
For k = 1 To ilen * 8
s2 = s2 & B(k)
If k Mod 8 = 0 Then
s2 = s2
End If
Next
bit2byte = s2
End Function
Public Function byte2bit(s)
Dim i, k, ilen
Dim by()
Dim B()
ilen = Len(s)
ReDim by(ilen)
ReDim B(ilen / 8)
For k = 1 To ilen
by(k) = Mid(s, k, 1)
Next
For i = 1 To (ilen / 8)
If by(1 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or &H80
Else
B(i) = B(i) And &H7F
End If
If by(2 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or &H40
Else
B(i) = B(i) And &HBF
End If
If by(3 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or &H20
Else
B(i) = B(i) And &HDF
End If
If by(4 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or &H10
Else
B(i) = B(i) And &HEF
End If
If by(5 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or &H8
Else
B(i) = B(i) And &HF7
End If
If by(6 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or &H4
Else
B(i) = B(i) And &HFB
End If
If by(7 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or &H2
Else
B(i) = B(i) And &HFD
End If
If by(8 + 8 * (i - 1)) = "1" Then
B(i) = B(i) Or "1"
Else
B(i) = B(i) And &HFE
End If
byte2bit = byte2bit & Chr(B(i))
Next
End Function
'asp 的DES加密文件(V6bbs修正版)
Public Function byte2hex(s)
Dim i, k, ilen
Dim by(), s1 , s3 , s4
Dim B()
ilen = Len(s)
ReDim by(ilen)
ReDim B(ilen / 4)
For k = 1 To ilen
by(k) = Mid(s, k, 1)
Next
For i = 1 To ilen / 4
B(i) = by(4 * i - 3) * 2 ^ 3 + by(4 * i - 2) * 2 ^ 2 + by(4 * i - 1) * 2 ^ 1 + by(4 * i) * 2 ^ 0
s1 = s1 & Hex(B(i))
If i Mod 4 = 0 Then
s1 = "&h" + s1
s3 = s3 & CStr(Hex(s1))
s1 = ""
s3 = "&h" + s3
s4 = s4 + Chr(s3)
s3 = ""
End If
Next
byte2hex = byte2hex & s4
End Function
Public Function hex2byte(s )
Dim s2
Dim x
Dim i , k
Dim s3()
Dim ilen
ilen = Len(s)
Dim B()
Dim s1()
ReDim s1(ilen)
ReDim B(ilen * 16)
s2 = ""
For i = 1 To ilen
x = Mid(s, i, 1)
s1(i) = "&h" + Hex(Asc(x))
If s1(i) And &H8000 Then
B(1 + 16 * (i - 1)) = 1
Else
B(1 + 16 * (i - 1)) = 0
End If
If s1(i) And &H4000 Then
B(2 + 16 * (i - 1)) = 1
Else
B(2 + 16 * (i - 1)) = 0
End If
If s1(i) And &H2000 Then
B(3 + 16 * (i - 1)) = 1
Else
B(3 + 16 * (i - 1)) = 0
End If
If s1(i) And &H1000 Then
B(4 + 16 * (i - 1)) = 1
Else
B(4 + 16 * (i - 1)) = 0
End If
If s1(i) And &H800 Then
B(5 + 16 * (i - 1)) = 1
Else
B(5 + 16 * (i - 1)) = 0
End If
If s1(i) And &H400 Then
B(6 + 16 * (i - 1)) = 1
Else
B(6 + 16 * (i - 1)) = 0
End If
If s1(i) And &H200 Then
B(7 + 16 * (i - 1)) = 1
Else
B(7 + 16 * (i - 1)) = 0
End If
If s1(i) And &H100 Then
B(8 + 16 * (i - 1)) = 1
Else
B(8 + 16 * (i - 1)) = 0
End If
If s1(i) And &H80 Then
B(9 + 16 * (i - 1)) = 1
Else
B(9 + 16 * (i - 1)) = 0
End If
If s1(i) And &H40 Then
B(10 + 16 * (i - 1)) = 1
Else
B(10 + 16 * (i - 1)) = 0
End If
If s1(i) And &H20 Then
B(11 + 16 * (i - 1)) = 1
Else
B(11 + 16 * (i - 1)) = 0
End If
If s1(i) And &H10 Then
B(12 + 16 * (i - 1)) = 1
Else
B(12 + 16 * (i - 1)) = 0
End If
If s1(i) And &H8 Then
B(13 + 16 * (i - 1)) = 1
Else
B(13 + 16 * (i - 1)) = 0
End If
If s1(i) And &H4 Then
B(14 + 16 * (i - 1)) = 1
Else
B(14 + 16 * (i - 1)) = 0
End If
If s1(i) And &H2 Then
B(15 + 16 * (i - 1)) = 1
Else
B(15 + 16 * (i - 1)) = 0
End If
If s1(i) And "1" Then
B(16 + 16 * (i - 1)) = 1
Else
B(16 + 16 * (i - 1)) = 0
End If
Next
For k = 1 To ilen * 16
s2 = s2 & B(k)
Next
hex2byte = s2
End Function
'asp 的DES加密文件(V6bbs修正版)
Public Function sbox(A )
Dim B(7) , A1(7) , row(7) , col(7)
Dim i , temp1(7) , temp2(7) , j , k
Dim s(7, 3, 15)
s(0, 0, 0) = 14: s(0, 0, 1) = 4: s(0, 0, 2) = 13: s(0, 0, 3) = 1: s(0, 0, 4) = 2: s(0, 0, 5) = 15: s(0, 0, 6) = 11: s(0, 0, 7) = 8: s(0, 0, 8) = 3: s(0, 0, 9) = 10: s(0, 0, 10) = 6: s(0, 0, 11) = 12: s(0, 0, 12) = 5: s(0, 0, 13) = 9: s(0, 0, 14) = 0: s(0, 0, 15) = 7
s(0, 1, 0) = 0: s(0, 1, 1) = 15: s(0, 1, 2) = 7: s(0, 1, 3) = 4: s(0, 1, 4) = 14: s(0, 1, 5) = 2: s(0, 1, 6) = 13: s(0, 1, 7) = 1: s(0, 1, 8) = 10: s(0, 1, 9) = 6: s(0, 1, 10) = 12: s(0, 1, 11) = 11: s(0, 1, 12) = 9: s(0, 1, 13) = 5: s(0, 1, 14) = 3: s(0, 1, 15) = 8
s(0, 2, 0) = 4: s(0, 2, 1) = 1: s(0, 2, 2) = 14: s(0, 2, 3) = 8: s(0, 2, 4) = 13: s(0, 2, 5) = 6: s(0, 2, 6) = 2: s(0, 2, 7) = 11: s(0, 2, 8) = 15: s(0, 2, 9) = 12: s(0, 2, 10) = 9: s(0, 2, 11) = 7: s(0, 2, 12) = 3: s(0, 2, 13) = 10: s(0, 2, 14) = 5: s(0, 2, 15) = 0
s(0, 3, 0) = 15: s(0, 3, 1) = 12: s(0, 3, 2) = 8: s(0, 3, 3) = 2: s(0, 3, 4) = 4: s(0, 3, 5) = 9: s(0, 3, 6) = 1: s(0, 3, 7) = 7: s(0, 3, 8) = 5: s(0, 3, 9) = 11: s(0, 3, 10) = 3: s(0, 3, 11) = 14: s(0, 3, 12) = 10: s(0, 3, 13) = 0: s(0, 3, 14) = 6: s(0, 3, 15) = 13
s(1, 0, 0) = 15: s(1, 0, 1) = 1: s(1, 0, 2) = 8: s(1, 0, 3) = 14: s(1, 0, 4) = 6: s(1, 0, 5) = 11: s(1, 0, 6) = 3: s(1, 0, 7) = 4: s(1, 0, 8) = 9: s(1, 0, 9) = 7: s(1, 0, 10) = 2: s(1, 0, 11) = 13: s(1, 0, 12) = 12: s(1, 0, 13) = 0: s(1, 0, 14) = 5: s(1, 0, 15) = 10
s(1, 1, 0) = 3: s(1, 1, 1) = 13: s(1, 1, 2) = 4: s(1, 1, 3) = 7: s(1, 1, 4) = 15: s(1, 1, 5) = 2: s(1, 1, 6) = 8: s(1, 1, 7) = 14: s(1, 1, 8) = 12: s(1, 1, 9) = 0: s(1, 1, 10) = 1: s(1, 1, 11) = 10: s(1, 1, 12) = 6: s(1, 1, 13) = 9: s(1, 1, 14) = 11: s(1, 1, 15) = 5
s(1, 2, 0) = 0: s(1, 2, 1) = 14: s(1, 2, 2) = 7: s(1, 2, 3) = 11: s(1, 2, 4) = 10: s(1, 2, 5) = 4: s(1, 2, 6) = 13: s(1, 2, 7) = 1: s(1, 2, 8) = 5: s(1, 2, 9) = 8: s(1, 2, 10) = 12: s(1, 2, 11) = 6: s(1, 2, 12) = 9: s(1, 2, 13) = 3: s(1, 2, 14) = 2: s(1, 2, 15) = 15
s(1, 3, 0) = 13: s(1, 3, 1) = 8: s(1, 3, 2) = 10: s(1, 3, 3) = 1: s(1, 3, 4) = 3: s(1, 3, 5) = 15: s(1, 3, 6) = 4: s(1, 3, 7) = 2: s(1, 3, 8) = 11: s(1, 3, 9) = 6: s(1, 3, 10) = 7: s(1, 3, 11) = 12: s(1, 3, 12) = 0: s(1, 3, 13) = 5: s(1, 3, 14) = 14: s(1, 3, 15) = 9
s(2, 0, 0) = 10: s(2, 0, 1) = 0: s(2, 0, 2) = 9: s(2, 0, 3) = 14: s(2, 0, 4) = 6: s(2, 0, 5) = 3: s(2, 0, 6) = 15: s(2, 0, 7) = 5: s(2, 0, 8) = 1: s(2, 0, 9) = 13: s(2, 0, 10) = 12: s(2, 0, 11) = 7: s(2, 0, 12) = 11: s(2, 0, 13) = 4: s(2, 0, 14) = 2: s(2, 0, 15) = 8
s(2, 1, 0) = 13: s(2, 1, 1) = 7: s(2, 1, 2) = 0: s(2, 1, 3) = 9: s(2, 1, 4) = 3: s(2, 1, 5) = 4: s(2, 1, 6) = 6: s(2, 1, 7) = 10: s(2, 1, 8) = 2: s(2, 1, 9) = 8: s(2, 1, 10) = 5: s(2, 1, 11) = 14: s(2, 1, 12) = 12: s(2, 1, 13) = 11: s(2, 1, 14) = 15: s(2, 1, 15) = 1
s(2, 2, 0) = 13: s(2, 2, 1) = 6: s(2, 2, 2) = 4: s(2, 2, 3) = 9: s(2, 2, 4) = 8: s(2, 2, 5) = 15: s(2, 2, 6) = 3: s(2, 2, 7) = 0: s(2, 2, 8) = 11: s(2, 2, 9) = 1: s(2, 2, 10) = 2: s(2, 2, 11) = 12: s(2, 2, 12) = 5: s(2, 2, 13) = 10: s(2, 2, 14) = 14: s(2, 2, 15) = 7
s(2, 3, 0) = 1: s(2, 3, 1) = 10: s(2, 3, 2) = 13: s(2, 3, 3) = 0: s(2, 3, 4) = 6: s(2, 3, 5) = 9: s(2, 3, 6) = 8: s(2, 3, 7) = 7: s(2, 3, 8) = 4: s(2, 3, 9) = 15: s(2, 3, 10) = 14: s(2, 3, 11) = 3: s(2, 3, 12) = 11: s(2, 3, 13) = 5: s(2, 3, 14) = 2: s(2, 3, 15) = 12
s(3, 0, 0) = 7: s(3, 0, 1) = 13: s(3, 0, 2) = 14: s(3, 0, 3) = 3: s(3, 0, 4) = 0: s(3, 0, 5) = 6: s(3, 0, 6) = 9: s(3, 0, 7) = 10: s(3, 0, 8) = 1: s(3, 0, 9) = 2: s(3, 0, 10) = 8: s(3, 0, 11) = 5: s(3, 0, 12) = 11: s(3, 0, 13) = 12: s(3, 0, 14) = 4: s(3, 0, 15) = 15
s(3, 1, 0) = 13: s(3, 1, 1) = 8: s(3, 1, 2) = 11: s(3, 1, 3) = 5: s(3, 1, 4) = 6: s(3, 1, 5) = 15: s(3, 1, 6) = 0: s(3, 1, 7) = 3: s(3, 1, 8) = 4: s(3, 1, 9) = 7: s(3, 1, 10) = 2: s(3, 1, 11) = 12: s(3, 1, 12) = 1: s(3, 1, 13) = 10: s(3, 1, 14) = 14: s(3, 1, 15) = 9
s(3, 2, 0) = 10: s(3, 2, 1) = 6: s(3, 2, 2) = 9: s(3, 2, 3) = 0: s(3, 2, 4) = 12: s(3, 2, 5) = 11: s(3, 2, 6) = 7: s(3, 2, 7) = 13: s(3, 2, 8) = 15: s(3, 2, 9) = 1: s(3, 2, 10) = 3: s(3, 2, 11) = 14: s(3, 2, 12) = 5: s(3, 2, 13) = 2: s(3, 2, 14) = 8: s(3, 2, 15) = 4
s(3, 3, 0) = 3: s(3, 3, 1) = 15: s(3, 3, 2) = 0: s(3, 3, 3) = 6: s(3, 3, 4) = 10: s(3, 3, 5) = 1: s(3, 3, 6) = 13: s(3, 3, 7) = 8: s(3, 3, 8) = 9: s(3, 3, 9) = 4: s(3, 3, 10) = 5: s(3, 3, 11) = 11: s(3, 3, 12) = 12: s(3, 3, 13) = 7: s(3, 3, 14) = 2: s(3, 3, 15) = 14
s(4, 0, 0) = 2: s(4, 0, 1) = 12: s(4, 0, 2) = 4: s(4, 0, 3) = 1: s(4, 0, 4) = 7: s(4, 0, 5) = 10: s(4, 0, 6) = 11: s(4, 0, 7) = 6: s(4, 0, 8) = 8: s(4, 0, 9) = 5: s(4, 0, 10) = 3: s(4, 0, 11) = 15: s(4, 0, 12) = 13: s(4, 0, 13) = 0: s(4, 0, 14) = 14: s(4, 0, 15) = 9
s(4, 1, 0) = 14: s(4, 1, 1) = 11: s(4, 1, 2) = 2: s(4, 1, 3) = 12: s(4, 1, 4) = 4: s(4, 1, 5) = 7: s(4, 1, 6) = 13: s(4, 1, 7) = 1: s(4, 1, 8) = 5: s(4, 1, 9) = 0: s(4, 1, 10) = 15: s(4, 1, 11) = 10: s(4, 1, 12) = 3: s(4, 1, 13) = 9: s(4, 1, 14) = 8: s(4, 1, 15) = 6
s(4, 2, 0) = 4: s(4, 3, 2) = 2: s(4, 2, 2) = 1: s(4, 2, 3) = 11: s(4, 2, 4) = 10: s(4, 2, 5) = 13: s(4, 2, 6) = 7: s(4, 2, 7) = 8: s(4, 2, 8) = 15: s(4, 2, 9) = 9: s(4, 2, 10) = 12: s(4, 2, 11) = 5: s(4, 2, 12) = 6: s(4, 2, 13) = 3: s(4, 2, 14) = 0: s(4, 2, 15) = 14
s(4, 3, 0) = 11: s(4, 3, 1) = 8: s(4, 3, 2) = 12: s(4, 3, 3) = 7: s(4, 3, 4) = 1: s(4, 3, 5) = 14: s(4, 3, 6) = 2: s(4, 3, 7) = 13: s(4, 3, 8) = 6: s(4, 3, 9) = 15: s(4, 3, 10) = 0: s(4, 3, 11) = 9: s(4, 3, 12) = 10: s(4, 3, 13) = 4: s(4, 3, 14) = 5: s(4, 3, 15) = 3
s(5, 0, 0) = 12: s(5, 0, 1) = 1: s(5, 0, 2) = 10: s(5, 0, 3) = 15: s(5, 0, 4) = 9: s(5, 0, 5) = 2: s(5, 0, 6) = 6: s(5, 0, 7) = 8: s(5, 0, 8) = 0: s(5, 0, 9) = 13: s(5, 0, 10) = 3: s(5, 0, 11) = 4: s(5, 0, 12) = 14: s(5, 0, 13) = 7: s(5, 0, 14) = 5: s(5, 0, 15) = 11
s(5, 1, 0) = 10: s(5, 1, 1) = 15: s(5, 1, 2) = 4: s(5, 1, 3) = 2: s(5, 1, 4) = 7: s(5, 1, 5) = 12: s(5, 1, 6) = 9: s(5, 1, 7) = 5: s(5, 1, 8) = 6: s(5, 1, 9) = 1: s(5, 1, 10) = 13: s(5, 1, 11) = 14: s(5, 1, 12) = 0: s(5, 1, 13) = 11: s(5, 1, 14) = 3: s(5, 1, 15) = 8
s(5, 2, 0) = 9: s(5, 2, 1) = 14: s(5, 2, 2) = 15: s(5, 2, 3) = 5: s(5, 2, 4) = 2: s(5, 2, 5) = 8: s(5, 2, 6) = 12: s(5, 2, 7) = 3: s(5, 2, 8) = 7: s(5, 2, 9) = 0: s(5, 2, 10) = 4: s(5, 2, 11) = 10: s(5, 2, 12) = 1: s(5, 2, 13) = 13: s(5, 2, 14) = 11: s(5, 2, 15) = 6
s(5, 3, 0) = 4: s(5, 3, 1) = 3: s(5, 3, 2) = 2: s(5, 3, 3) = 12: s(5, 3, 4) = 9: s(5, 3, 5) = 5: s(5, 3, 6) = 15: s(5, 3, 7) = 10: s(5, 3, 8) = 11: s(5, 3, 9) = 14: s(5, 3, 10) = 1: s(5, 3, 11) = 7: s(5, 3, 12) = 6: s(5, 3, 13) = 0: s(5, 3, 14) = 8: s(5, 3, 15) = 13
s(6, 0, 0) = 4: s(6, 0, 1) = 11: s(6, 0, 2) = 2: s(6, 0, 3) = 14: s(6, 0, 4) = 15: s(6, 0, 5) = 0: s(6, 0, 6) = 8: s(6, 0, 7) = 13: s(6, 0, 8) = 3: s(6, 0, 9) = 12: s(6, 0, 10) = 9: s(6, 0, 11) = 7: s(6, 0, 12) = 5: s(6, 0, 13) = 10: s(6, 0, 14) = 6: s(6, 0, 15) = 1
s(6, 1, 0) = 13: s(6, 1, 1) = 0: s(6, 1, 2) = 11: s(6, 1, 3) = 7: s(6, 1, 4) = 4: s(6, 1, 5) = 9: s(6, 1, 6) = 1: s(6, 1, 7) = 10: s(6, 1, 8) = 14: s(6, 1, 9) = 3: s(6, 1, 10) = 5: s(6, 1, 11) = 12: s(6, 1, 12) = 2: s(6, 1, 13) = 15: s(6, 1, 14) = 8: s(6, 1, 15) = 6
s(6, 2, 0) = 1: s(6, 2, 1) = 4: s(6, 2, 2) = 11: s(6, 2, 3) = 13: s(6, 2, 4) = 12: s(6, 2, 5) = 3: s(6, 2, 6) = 7: s(6, 2, 7) = 14: s(6, 2, 8) = 10: s(6, 2, 9) = 15: s(6, 2, 10) = 6: s(6, 2, 11) = 8: s(6, 2, 12) = 0: s(6, 2, 13) = 5: s(6, 2, 14) = 9: s(6, 2, 15) = 2
s(6, 3, 0) = 6: s(6, 3, 1) = 11: s(6, 3, 2) = 13: s(6, 3, 3) = 8: s(6, 3, 4) = 1: s(6, 3, 5) = 4: s(6, 3, 6) = 10: s(6, 3, 7) = 7: s(6, 3, 8) = 9: s(6, 3, 9) = 5: s(6, 3, 10) = 0: s(6, 3, 11) = 15: s(6, 3, 12) = 14: s(6, 3, 13) = 2: s(6, 3, 14) = 3: s(6, 3, 15) = 12
s(7, 0, 0) = 13: s(7, 0, 1) = 2: s(7, 0, 2) = 8: s(7, 0, 3) = 4: s(7, 0, 4) = 6: s(7, 0, 5) = 15: s(7, 0, 6) = 11: s(7, 0, 7) = 1: s(7, 0, 8) = 10: s(7, 0, 9) = 9: s(7, 0, 10) = 3: s(7, 0, 11) = 14: s(7, 0, 12) = 5: s(7, 0, 13) = 0: s(7, 0, 14) = 12: s(7, 0, 15) = 7
s(7, 1, 0) = 1: s(7, 1, 1) = 15: s(7, 1, 2) = 13: s(7, 1, 3) = 8: s(7, 1, 4) = 10: s(7, 1, 5) = 3: s(7, 1, 6) = 7: s(7, 1, 7) = 4: s(7, 1, 8) = 12: s(7, 1, 9) = 5: s(7, 1, 10) = 6: s(7, 1, 11) = 11: s(7, 1, 12) = 0: s(7, 1, 13) = 14: s(7, 1, 14) = 9: s(7, 1, 15) = 2
s(7, 2, 0) = 7: s(7, 2, 1) = 11: s(7, 2, 2) = 4: s(7, 2, 3) = 1: s(7, 2, 4) = 9: s(7, 2, 5) = 12: s(7, 2, 6) = 14: s(7, 2, 7) = 2: s(7, 2, 8) = 0: s(7, 2, 9) = 6: s(7, 2, 10) = 10: s(7, 2, 11) = 13: s(7, 2, 12) = 15: s(7, 2, 13) = 3: s(7, 2, 14) = 5: s(7, 2, 15) = 8
s(7, 3, 0) = 2: s(7, 3, 1) = 1: s(7, 3, 2) = 14: s(7, 3, 3) = 7: s(7, 3, 4) = 4: s(7, 3, 5) = 10: s(7, 3, 6) = 8: s(7, 3, 7) = 13: s(7, 3, 8) = 15: s(7, 3, 9) = 12: s(7, 3, 10) = 9: s(7, 3, 11) = 0: s(7, 3, 12) = 3: s(7, 3, 13) = 5: s(7, 3, 14) = 6: s(7, 3, 15) = 11
For i = 0 To 7
col(i) = 0: row(i) = 0
Next
For k = 0 To 7
A1(k) = Mid(A, 6 * k + 1, 6)
temp1(k) = Mid(A1(k), 1, 1) & Mid(A1(k), 6, 1)
temp2(k) = Mid(A1(k), 2, 4)
row(k) = (CInt(Mid(temp1(k), 1, 1))) * 2 + CInt((Mid(temp1(k), 2, 1)))
col(k) = CInt(Mid(temp2(k), 1, 1)) * 2 ^ 3 + CInt(Mid(temp2(k), 2, 1)) * 2 ^ 2 + CInt(Mid(temp2(k), 3, 1)) * 2 ^ 1 + CInt(Mid(temp2(k), 4, 1)) * 2 ^ 0 + col(k)
Next
For i = 0 To 7
B(i) = s(i, row(i), col(i))
If B(i) And &H8 Then
sbox = sbox & 1
Else
sbox = sbox & 0 <, br> End If
If B(i) And &H4 Then
sbox = sbox & 1
Else
sbox = sbox & 0
End If
If B(i) And &H2 Then
sbox = sbox & 1
Else
sbox = sbox & 0
End If
If B(i) And &H1 Then
sbox = sbox & 1
Else
sbox = sbox & 0
End If
Next
End Function
Public Function sk(s )
Dim s1 : Dim ls(16) : Dim pc_2(48) : Dim pc_1(56) , s2_byte1(56)
Dim i , c(28) , d(28) , s2(64) , j , s2_byte(56) , k , temp
Dim m_bit(64)
ls(1) = 1: ls(2) = 1: ls(3) = 2: ls(4) = 2: ls(5) = 2: ls(6) = 2: ls(7) = 2: ls(8) = 2: ls(9) = 1: ls(10) = 2: ls(11) = 2: ls(12) = 2: ls(13) = 2: ls(14) = 2: ls(15) = 2: ls(16) = 1
pc_2(1) = 14: pc_2(2) = 17: pc_2(3) = 11: pc_2(4) = 24: pc_2(5) = 1: pc_2(6) = 5
pc_2(7) = 3: pc_2(8) = 28: pc_2(9) = 15: pc_2(10) = 6: pc_2(11) = 21: pc_2(12) = 10
pc_2(13) = 23: pc_2(14) = 19: pc_2(15) = 12: pc_2(16) = 4: pc_2(17) = 26: pc_2(18) = 8
pc_2(19) = 16: pc_2(20) = 7: pc_2(21) = 27: pc_2(22) = 20: pc_2(23) = 13: pc_2(24) = 2
pc_2(25) = 41: pc_2(26) = 52: pc_2(27) = 31: pc_2(28) = 37: pc_2(29) = 47: pc_2(30) = 55
pc_2(31) = 30: pc_2(32) = 40: pc_2(33) = 51: pc_2(34) = 45: pc_2(35) = 33: pc_2(36) = 48
pc_2(37) = 44: pc_2(38) = 49: pc_2(39) = 39: pc_2(40) = 56: pc_2(41) = 34: pc_2(42) = 53
pc_2(43) = 46: pc_2(44) = 42: pc_2(45) = 50: pc_2(46) = 36: pc_2(47) = 29: pc_2(48) = 32
pc_1(1) = 57: pc_1(2) = 49: pc_1(3) = 41: pc_1(4) = 33: pc_1(5) = 25: pc_1(6) = 17: pc_1(7) = 9
pc_1(8) = 1: pc_1(9) = 58: pc_1(10) = 50: pc_1(11) = 42: pc_1(12) = 34: pc_1(13) = 26: pc_1(14) = 18
pc_1(15) = 10: pc_1(16) = 2: pc_1(17) = 59: pc_1(18) = 51: pc_1(19) = 43: pc_1(20) = 35: pc_1(21) = 27
pc_1(22) = 19: pc_1(23) = 11: pc_1(24) = 3: pc_1(25) = 60: pc_1(26) = 52: pc_1(27) = 44: pc_1(28) = 36
pc_1(29) = 63: pc_1(30) = 55: pc_1(31) = 47: pc_1(32) = 39: pc_1(33) = 31: pc_1(34) = 23: pc_1(35) = 15
pc_1(36) = 7: pc_1(37) = 62: pc_1(38) = 54: pc_1(39) = 46: pc_1(40) = 38: pc_1(41) = 30: pc_1(42) = 22
pc_1(43) = 14: pc_1(44) = 6: pc_1(45) = 61: pc_1(46) = 53: pc_1(47) = 45: pc_1(48) = 37: pc_1(49) = 29
pc_1(50) = 21: pc_1(51) = 13: pc_1(52) = 5: pc_1(53) = 28: pc_1(54) = 20: pc_1(55) = 12: pc_1(56) = 4
s1 = bit2byte(s)
For i = 1 To 64
s2(i) = CInt(Mid(s1, i, 1))
Next
For i = 1 To 56
s2_byte(i) = s2(pc_1(i))
Next
For i = 1 To 28
c(i) = s2_byte(i)
d(i) = s2_byte(i + 28)
Next
For i = 1 To 16
For j = 1 To ls(i)
temp = c(1)
For k = 1 To 27
c(k) = c(k + 1)
Next
c(28) = temp
temp = d(1)
For k = 1 To 27
d(k) = d(k + 1)
Next
d(28) = temp
Next
For k = 1 To 28
s2_byte1(k) = c(k)
s2_byte1(k + 28) = d(k)
Next
For k = 1 To 48
sk = sk & s2_byte1(pc_2(k))
Next
Next
End Function
Dim ens,destr
ens=Encrypt("?","12345678"
Response.Write(ens & "<br />"
destr=decrypt(ens,"12345678"
Response.Write(destr)
Public Function Encrypt(s , key )
Dim ip(64) , e(48) , s1(64) , s2(16) , s10(64) , m_byte1(64) , key1
Dim i , j , l(17, 32) , r(17, 32) , er(48) , m_byte(64) , s_b
Dim k(16, 48) , A , bs , B(32) , p(32) , x(32) , ip_1(64)
Dim ilen
p(1) = 16: p(2) = 7: p(3) = 20: p(4) = 21: p(5) = 29: p(6) = 12: p(7) = 28: p(8) = 17
p(9) = 1: p(10) = 15: p(11) = 23: p(12) = 26: p(13) = 5: p(14) = 18: p(15) = 31: p(16) = 10
p(17) = 2: p(18) = 8: p(19) = 24: p(20) = 14: p(21) = 32: p(22) = 27: p(23) = 3: p(24) = 9
p(25) = 19: p(26) = 13: p(27) = 30: p(28) = 6: p(29) = 22: p(30) = 11: p(31) = 4: p(32) = 25
ip_1(1) = 40: ip_1(2) = 8: ip_1(3) = 48: ip_1(4) = 16: ip_1(5) = 56: ip_1(6) = 24: ip_1(7) = 64: ip_1(8) = 32
ip_1(9) = 39: ip_1(10) = 7: ip_1(11) = 47: ip_1(12) = 15: ip_1(13) = 55: ip_1(14) = 23: ip_1(15) = 63: ip_1(16) = 31
ip_1(17) = 38: ip_1(18) = 6: ip_1(19) = 46: ip_1(20) = 14: ip_1(21) = 54: ip_1(22) = 22: ip_1(23) = 62: ip_1(24) = 30
ip_1(25) = 37: ip_1(26) = 5: ip_1(27) = 45: ip_1(28) = 13: ip_1(29) = 53: ip_1(30) = 21: ip_1(31) = 61: ip_1(32) = 29
ip_1(33) = 36: ip_1(34) = 4: ip_1(35) = 44: ip_1(36) = 12: ip_1(37) = 52: ip_1(38) = 20: ip_1(39) = 60: ip_1(40) = 28
ip_1(41) = 35: ip_1(42) = 3: ip_1(43) = 43: ip_1(44) = 11: ip_1(45) = 51: ip_1(46) = 19: ip_1(47) = 59: ip_1(48) = 27
ip_1(49) = 34: ip_1(50) = 2: ip_1(51) = 42: ip_1(52) = 10: ip_1(53) = 50: ip_1(54) = 18: ip_1(55) = 58: ip_1(56) = 26
ip_1(57) = 33: ip_1(58) = 1: ip_1(59) = 41: ip_1(60) = 9: ip_1(61) = 49: ip_1(62) = 17: ip_1(63) = 57: ip_1(64) = 25
ip(1) = 58: ip(2) = 50: ip(3) = 42: ip(4) = 34: ip(5) = 26: ip(6) = 18: ip(7) = 10: ip(8) = 2
ip(9) = 60: ip(10) = 52: ip(11) = 44: ip(12) = 36: ip(13) = 28: ip(14) = 20: ip(15) = 12: ip(16) = 4
ip(17) = 62: ip(18) = 54: ip(19) = 46: ip(20) = 38: ip(21) = 30: ip(22) = 22: ip(23) = 14: ip(24) = 6
ip(25) = 64: ip(26) = 56: ip(27) = 48: ip(28) = 40: ip(29) = 32: ip(30) = 24: ip(31) = 16: ip(32) = 8
ip(33) = 57: ip(34) = 49: ip(35) = 41: ip(36) = 33: ip(37) = 25: ip(38) = 17: ip(39) = 9: ip(40) = 1
ip(41) = 59: ip(42) = 51: ip(43) = 43: ip(44) = 35: ip(45) = 27: ip(46) = 19: ip(47) = 11: ip(48) = 3
ip(49) = 61: ip(50) = 53: ip(51) = 45: ip(52) = 37: ip(53) = 29: ip(54) = 21: ip(55) = 13: ip(56) = 5
ip(57) = 63: ip(58) = 55: ip(59) = 47: ip(60) = 39: ip(61) = 31: ip(62) = 23: ip(63) = 15: ip(64) = 7
e(1) = 32: e(2) = 1: e(3) = 2: e(4) = 3: e(5) = 4: e(6) = 5
e(7) = 4: e(8) = 5: e(9) = 6: e(10) = 7: e(11) = 8: e(12) = 9
e(13) = 8: e(14) = 9: e(15) = 10: e(16) = 11: e(17) = 12: e(18) = 13
e(19) = 12: e(20) = 13: e(21) = 14: e(22) = 15: e(23) = 16: e(24) = 17
e(25) = 16: e(26) = 17: e(27) = 18: e(28) = 19: e(29) = 20: e(30) = 21
e(31) = 20: e(32) = 21: e(33) = 22: e(34) = 23: e(35) = 24: e(36) = 25
e(37) = 24: e(38) = 25: e(39) = 26: e(40) = 27: e(41) = 28: e(42) = 29
e(43) = 28: e(44) = 29: e(45) = 30: e(46) = 31: e(47) = 32: e(48) = 31
key1 = sk(key)
For i = 1 To 16
s2(i) = Mid(key1, 48 * i - 47, 48)
Next
For i = 1 To 16
For j = 1 To 48
k(i, j) = CInt(Mid(s2(i), j, 1))
Next
Next
s_b = hex2byte(s)
ilen = Len(s_b)
For i = 1 To ilen-1
s1(i) = CInt(Mid(s_b, i, 1))
Next
For i = 1 To 64
s10(i) = s1(ip(i))
Next
For i = 1 To 32
l(1, i) = s10(i)
r(1, i) = s10(i + 32)
Next
For j = 1 To 16
A = ""
For i = 1 To 48
er(i) = r(j, e(i))
Next
For i = 1 To 48
A = A & (er(i) Xor k(j, i))
Next
bs = sbox(A)
For i = 1 To 32
B(i) = CInt(Mid(bs, i, 1))
Next
For i = 1 To 32
x(i) = B(p(i))
Next
For i = 1 To 32
r(j + 1, i) = l(j, i) Xor x(i)
l(j + 1, i) = r(j, i)
Next
Next
For i = 1 To 32
m_byte(i) = l(17, i)
m_byte(i + 32) = r(17, i)
Next
For i = 1 To 64
m_byte1(i) = m_byte(ip_1(i))
Encrypt = Encrypt & m_byte1(i)
Next
End Function
Public Function decrypt(sm , key )
Dim p(32) , ip_1(64) , ip(64) , e(48) , s10(64) , er(48)
Dim j , key1 , s2(16) , k(16, 48) , s1(64) , l(17, 32) , r(17, 32)
Dim i , A , bs , B(32) , x(32) , e_byte(64) , e_byte1(64)
Dim ilen
p(1) = 16: p(2) = 7: p(3) = 20: p(4) = 21: p(5) = 29: p(6) = 12: p(7) = 28: p(8) = 17
p(9) = 1: p(10) = 15: p(11) = 23: p(12) = 26: p(13) = 5: p(14) = 18: p(15) = 31: p(16) = 10
p(17) = 2: p(18) = 8: p(19) = 24: p(20) = 14: p(21) = 32: p(22) = 27: p(23) = 3: p(24) = 9
p(25) = 19: p(26) = 13: p(27) = 30: p(28) = 6: p(29) = 22: p(30) = 11: p(31) = 4: p(32) = 25
ip_1(1) = 40: ip_1(2) = 8: ip_1(3) = 48: ip_1(4) = 16: ip_1(5) = 56: ip_1(6) = 24: ip_1(7) = 64: ip_1(8) = 32
ip_1(9) = 39: ip_1(10) = 7: ip_1(11) = 47: ip_1(12) = 15: ip_1(13) = 55: ip_1(14) = 23: ip_1(15) = 63: ip_1(16) = 31
ip_1(17) = 38: ip_1(18) = 6: ip_1(19) = 46: ip_1(20) = 14: ip_1(21) = 54: ip_1(22) = 22: ip_1(23) = 62: ip_1(24) = 30
ip_1(25) = 37: ip_1(26) = 5: ip_1(27) = 45: ip_1(28) = 13: ip_1(29) = 53: ip_1(30) = 21: ip_1(31) = 61: ip_1(32) = 29
ip_1(33) = 36: ip_1(34) = 4: ip_1(35) = 44: ip_1(36) = 12: ip_1(37) = 52: ip_1(38) = 20: ip_1(39) = 60: ip_1(40) = 28
ip_1(41) = 35: ip_1(42) = 3: ip_1(43) = 43: ip_1(44) = 11: ip_1(45) = 51: ip_1(46) = 19: ip_1(47) = 59: ip_1(48) = 27
ip_1(49) = 34: ip_1(50) = 2: ip_1(51) = 42: ip_1(52) = 10: ip_1(53) = 50: ip_1(54) = 18: ip_1(55) = 58: ip_1(56) = 26
ip_1(57) = 33: ip_1(58) = 1: ip_1(59) = 41: ip_1(60) = 9: ip_1(61) = 49: ip_1(62) = 17: ip_1(63) = 57: ip_1(64) = 25
ip(1) = 58: ip(2) = 50: ip(3) = 42: ip(4) = 34: ip(5) = 26: ip(6) = 18: ip(7) = 10: ip(8) = 2
ip(9) = 60: ip(10) = 52: ip(11) = 44: ip(12) = 36: ip(13) = 28: ip(14) = 20: ip(15) = 12: ip(16) = 4
ip(17) = 62: ip(18) = 54: ip(19) = 46: ip(20) = 38: ip(21) = 30: ip(22) = 22: ip(23) = 14: ip(24) = 6
ip(25) = 64: ip(26) = 56: ip(27) = 48: ip(28) = 40: ip(29) = 32: ip(30) = 24: ip(31) = 16: ip(32) = 8
ip(33) = 57: ip(34) = 49: ip(35) = 41: ip(36) = 33: ip(37) = 25: ip(38) = 17: ip(39) = 9: ip(40) = 1
ip(41) = 59: ip(42) = 51: ip(43) = 43: ip(44) = 35: ip(45) = 27: ip(46) = 19: ip(47) = 11: ip(48) = 3
ip(49) = 61: ip(50) = 53: ip(51) = 45: ip(52) = 37: ip(53) = 29: ip(54) = 21: ip(55) = 13: ip(56) = 5
ip(57) = 63: ip(58) = 55: ip(59) = 47: ip(60) = 39: ip(61) = 31: ip(62) = 23: ip(63) = 15: ip(64) = 7
e(1) = 32: e(2) = 1: e(3) = 2: e(4) = 3: e(5) = 4: e(6) = 5
e(7) = 4: e(8) = 5: e(9) = 6: e(10) = 7: e(11) = 8: e(12) = 9
e(13) = 8: e(14) = 9: e(15) = 10: e(16) = 11: e(17) = 12: e(18) = 13
e(19) = 12: e(20) = 13: e(21) = 14: e(22) = 15: e(23) = 16: e(24) = 17
e(25) = 16: e(26) = 17: e(27) = 18: e(28) = 19: e(29) = 20: e(30) = 21
e(31) = 20: e(32) = 21: e(33) = 22: e(34) = 23: e(35) = 24: e(36) = 25
e(37) = 24: e(38) = 25: e(39) = 26: e(40) = 27: e(41) = 28: e(42) = 29
e(43) = 28: e(44) = 29: e(45) = 30: e(46) = 31: e(47) = 32: e(48) = 31
key1 = sk(key)
For i = 1 To 16
s2(i) = Mid(key1, 48 * i - 47, 48)
Next
For i = 1 To 16
For j = 1 To 48
k(i, j) = CInt(Mid(s2(i), j, 1))
Next
Next
ilen = Len(sm)
For i = 1 To ilen
s1(i) = CInt(Mid(sm, i, 1))
Next
For i = 1 To 64
s10(i) = s1(ip(i))
Next
For i = 1 To 32
l(1, i) = s10(i + 32)
r(1, i) = s10(i)
Next
For j = 1 To 16
A = ""
For i = 1 To 32
l(j + 1, i) = r(j, i)
Next
For i = 1 To 48
er(i) = r(j, e(i))
Next
For i = 1 To 48
A = A & (er(i) Xor k(17 - j, i))
Next
bs = sbox(A)
For i = 1 To 32
B(i) = CInt(Mid(bs, i, 1))
Next
For i = 1 To 32
x(i) = B(p(i))
Next
For i = 1 To 32
r(j + 1, i) = l(j, i) Xor x(i)
Next
Next
For i = 1 To 32
e_byte(i) = r(17, i)
e_byte(i + 32) = l(17, i)
Next
For i = 1 To 64
e_byte1(i) = e_byte(ip_1(i))
decrypt = decrypt & e_byte1(i)
Next
End Function
'asp 的DES加密文件(V6bbs修正版)
%>