|
楼主 |
发表于 2009-1-3 22:54
|
显示全部楼层
安全性较高的加密方案.
Function jami(XX, YY) As String
Dim datx() As Byte, datx1() As Byte
Dim daty() As Byte
Dim X As String, y As String, h As Long
X = XX
y = YY
daty = y
If "jami@" = Mid(X, 1, 5) Then
X = Mid(X, 6, Len(X))
arr = Split(X, " ")
ReDim datx(UBound(arr)) As Byte
For i = 0 To UBound(arr)
datx(i) = arr(i)
Next i
Else
datx = X
For i = 0 To UBound(datx) - 1 Step 2
If datx(i) = 255 And datx(i + 1) = 255 Then
datx(i) = 0: datx(i + 1) = 0
End If
Next i
End If
j = 0
datx1 = datx
For i = 0 To UBound(datx)
If j > UBound(daty) Then j = 0
datx(i) = datx(i) Xor daty(j)
j = j + 1
Next i
For i = UBound(datx) - 1 To 2 Step -2
h = datx(i)
h = Abs(h - datx1(i))
datx(i - 2) = datx(i - 2) Xor h
Next i
For i = 0 To UBound(datx) - 1 Step 2 '这里便是存在问题的根源,但又不得不这样做,要不然存入EXCEL单无格之后不能保持文本的原样.
If datx(i) = 0 And datx(i + 1) = 0 Then
datx(i) = 255: datx(i + 1) = 255
End If
Next i
jami = datx
If jami2(jami, y) <> XX And "jami@" <> Mid(XX, 1, 5) Then '加密后用解密进行验证,如果出错,换数字的方式来显示.
datx = datx1
j = 0
For i = 0 To UBound(datx)
If j > UBound(daty) Then j = 0
datx(i) = datx(i) Xor daty(j)
j = j + 1
Next i
For i = UBound(datx) - 1 To 2 Step -2
h = datx(i)
h = Abs(h - datx1(i))
datx(i - 2) = datx(i - 2) Xor h
Next i
X = datx(0)
For i = 1 To UBound(datx)
X = X & " " & datx(i)
Next i
jami = "jami@" & X
End If
End Function
Function jami2(XX, YY) As String '存在65536分之1的错误机率的加密方法,这里主要用来还原验证
Dim datx() As Byte, datx1() As Byte
Dim daty() As Byte
Dim X As String, y As String, h As Long
X = XX
y = YY
datx = X
daty = y
j = 0
For i = 0 To UBound(datx) - 1 Step 2
If datx(i) = 255 And datx(i + 1) = 255 Then
datx(i) = 0: datx(i + 1) = 0
End If
Next i
datx1 = datx
For i = 0 To UBound(datx)
If j > UBound(daty) Then j = 0
datx(i) = datx(i) Xor daty(j)
j = j + 1
Next i
For i = UBound(datx) - 1 To 2 Step -2
h = datx(i)
h = Abs(h - datx1(i))
datx(i - 2) = datx(i - 2) Xor h
Next i
For i = 0 To UBound(datx) - 1 Step 2
If datx(i) = 0 And datx(i + 1) = 0 Then
datx(i) = 255: datx(i + 1) = 255
End If
Next i
jami2 = datx
End Function
[ 本帖最后由 彭希仁 于 2009-1-3 23:33 编辑 ] |
|