
2、这里只进行一次异或运算,如有需要可以进行多次异或运算。
3、此加密算法速度快,当然加密强度也低 ;
参考代码如下:
1
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
34
35
36
37
38
39
40
41
42
43
44
'-----------------------------------------------------------------------
'函数说明: 使用异或运算加密文件(可加密大部分文件)
'参数说明: key - 密钥
' fileName - 普通文件名,
' encryptFileName - 加密后的文件名
'返回值: true - 成功,false - 失败
'-----------------------------------------------------------------------
Private Function XOR_Encrypt(key As Integer, fileName As String, encryptFileName As String) As Boolean
On Error GoTo errHandler
Dim inputFileNo As Integer
Dim fileBytes() As Byte
Dim length As Long
XOR_Encrypt = False
'打开文件并保存在二进制数组中
inputFileNo = FreeFile
Open fileName For Binary As #inputFileNo
length = LOF(inputFileNo)
If length = 0 Then
MsgBox "退出加密:文件内容为空!", vbInformation, "提示"
Exit Function
End If
ReDim fileBytes(length - 1) As Byte
Get inputFileNo, , fileBytes()
Close #inputFileNo
'将该二进制数组进行异或加密
Dim i As Long
For i = LBound(fileBytes) To UBound(fileBytes)
fileBytes(i) = fileBytes(i) Xor key
Next
'将异或加密后的二进制数组保存在新的文件中
Dim outputFileNo As Integer
outputFileNo = FreeFile
Open encryptFileName For Binary As #outputFileNo
Put outputFileNo, , fileBytes
Close #outputFileNo
XOR_Encrypt = True
errHandler:
If Err.Number Then
MsgBox "加密过程中出错:" &Err.Description, vbCritical, "错误"
XOR_Encrypt = False
Resume Next
End If
End Function
分类: 电脑/网络 >>程序设计 >>其他编程语言问题描述:
我是用Open "C:\..." For OutPut As #1这种方法保存的,我想让别人用记事本打开的时候变成乱码。
解析:
先将字符转换为数值,用asc函数
再将数值进行运算,比如:原数值+5,记住不要超过范围
再将数值转换为字符,用chr函数
还可以用二进制的方式保存,用open "C:\.." for binary as #1,二进制的那个单词可能有误
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)