level 6
cy9934303
楼主
随机函数是取得的随机数是伪随机,所以可以用数字密码作为随机函数的种子来对byte()打乱顺序,生成的文件乱码也没有规律,对于加密小文件的初级方法是个不错的选择。
Public Function 字节数组加密(ByVal bytes() As Byte) As Byte()
Dim a As New Random(bytes.Length)’bytes.Length是种子,可以设成密码
Dim index(Int(bytes.Length - 1 / 4) * 2)‘定义打乱次数,必须是偶数,这里是打乱Byte()长度的四分之一次
For i = 0 To Int(bytes.Length - 1 / 4) * 2 - 1
index(i) = a.Next(0, bytes.Length)’生成要打乱的byte()的标号
Next
Dim tmp%
For i = 0 To index.Length - 3 Step +2‘开始两组两组打乱
tmp = bytes(index(i))
bytes(index(i)) = bytes(index(i + 1))
bytes(index(i + 1)) = tmp
Next
Return bytes
End Function
Public Function 字节数组解密(ByVal bytes() As Byte) As Byte()
Dim a As New Random(bytes.Length)’bytes.Length是种子,可以设成密码
Dim index(Int(bytes.Length - 1 / 4) * 2)’同加密
For i = Int(bytes.Length - 1 / 4) * 2 - 1 To 0 Step -1
index(i) = a.Next(0, bytes.Length)
Next
Dim tmp%
For i = 0 To index.Length - 3 Step +2
tmp = bytes(index(i))
bytes(index(i)) = bytes(index(i + 1))
bytes(index(i + 1)) = tmp
Next
Return bytes
End Function
2016年06月18日 00点06分
1
Public Function 字节数组加密(ByVal bytes() As Byte) As Byte()
Dim a As New Random(bytes.Length)’bytes.Length是种子,可以设成密码
Dim index(Int(bytes.Length - 1 / 4) * 2)‘定义打乱次数,必须是偶数,这里是打乱Byte()长度的四分之一次
For i = 0 To Int(bytes.Length - 1 / 4) * 2 - 1
index(i) = a.Next(0, bytes.Length)’生成要打乱的byte()的标号
Next
Dim tmp%
For i = 0 To index.Length - 3 Step +2‘开始两组两组打乱
tmp = bytes(index(i))
bytes(index(i)) = bytes(index(i + 1))
bytes(index(i + 1)) = tmp
Next
Return bytes
End Function
Public Function 字节数组解密(ByVal bytes() As Byte) As Byte()
Dim a As New Random(bytes.Length)’bytes.Length是种子,可以设成密码
Dim index(Int(bytes.Length - 1 / 4) * 2)’同加密
For i = Int(bytes.Length - 1 / 4) * 2 - 1 To 0 Step -1
index(i) = a.Next(0, bytes.Length)
Next
Dim tmp%
For i = 0 To index.Length - 3 Step +2
tmp = bytes(index(i))
bytes(index(i)) = bytes(index(i + 1))
bytes(index(i + 1)) = tmp
Next
Return bytes
End Function