Public Const GENKEY = &H18 '//密钥
Public Function CodeFile(ByVal lpSrcFile As String, _
ByVal lpDesFile As String) As Boolean
CodeFile = False
On Error GoTo ErrHandle:
If Dir(lpSrcFile) <> "" Then
Dim FileSize As Long, FileNumber As Integer
FileSize = FileLen(lpSrcFile)
Dim arrbytes() As Byte, j As Long
ReDim arrbytes(1 To FileSize) As Byte
FileNumber = FreeFile
'//打开源文件
Open lpSrcFile For Binary Access Read As #FileNumber
Get #FileNumber, , arrbytes()
Close #FileNumber
'//对每一字节进行异或处理
For j = 1 To FileSize
arrbytes(j) = Abs(arrbytes(j) Xor GENKEY)
Next j
'//写入目标文件
Open lpDesFile For Binary Access Write As #FileNumber
Put #FileNumber, , arrbytes()
Close #FileNumber
CodeFile = True
End If
ErrHandle:
End Function
Sub Main()
If CodeFile("c:/file.txt", "c:/file_enc.txt") = True Then
MsgBox "加密成功", vbInformation, "成功"
Else
MsgBox "加密失败", vbExclamation, "失败"
End If
End Sub

6692




被折叠的 条评论
为什么被折叠?



