急求:vb 加密解密

来源:百度知道 编辑:UC知道 时间:2024/06/07 17:27:07
(1)编写一加密解密的程序,要求在选定文本文件后,对文件中所有字符进行加密,加密后文件保存为另一个文本文件,也可以选择被加密后的文件进行解密
(2)需求采用运算符XOR,至少要比程序中增加使用三个控件对象
(3)综合运用多种文件控件
(4)对文件中的字符采用逐字加密解密的方法

看看这个,控件要自己添加的

在窗体上添加文件控件:Drive控件,Dir控件,File控件,以及Command控件

程序过程:每次用Xor加密解密后,在文件名加上前缀X-,然后另外保存

Private Sub Command1_Click()
Dim oldFile As String, newfile As String, theByte As Byte
If File1.FileName = "" Then MsgBox "请选择需要加密或解密的文件!": Exit Sub
oldFile = Dir1.Path & "\" & File1.FileName
newfile = Dir1.Path & "\X-" & File1.FileName
Open oldFile For Binary As #1 Len = 1
Open newfile For Binary As #2
Do
Get #1, , theByte
theByte = 7 Xor theByte
Put #2, , theByte
Loop Until EOF(1)
Close #1
Close #2
MsgBox "加密或解密后的文件存放在“" & newfile & "”中!"
File1.Refresh
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Form_Load()
File1.Pattern = "*.txt" '只列出txt文本文件,如果要列出全