打开文件,加密/解密!
试问各路高参,如何在VB的程序中打开我想要的文本文件?并且在程序中可以看到。(10分)另外如何对它加密/解密(10分)先谢谢各位了! 问题点数:20、回复次数:6Top
1 楼PM0115(C++ing)回复于 2002-01-25 11:16:32 得分 0
附加一句,请给出主要的源代码!!!Top
2 楼chsl918(Story Book)回复于 2002-01-25 11:28:48 得分 10
加密,解密我刚刚做了一个东东放在昨天的帖子中
http://www.csdn.net/expert/topic/496/496920.shtm
二进制都可以,文本更是没问题了!
另外文本文件的读取,不要参照加密读取,那个是二进制读取Top
3 楼thirdapple(.:RNPA:.陨落雕 - 芝兰宝树)回复于 2002-01-25 11:40:58 得分 5
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Dim strFileName As String
Dim i As Long
Dim Databuff() As Byte
Dim Addbuff() As Byte
Dim Password() As Byte
Dim Code As String
Dim A As String
Private Sub Command1_Click()
Code = InputBox("请再输入一次:", "密码核定")
If Text1.Text = Val(Code) Then
Dim j As Integer
Dim Password_len As Integer
Password_len = Len(Text1.Text)
ReDim Password(Password_len) As Byte
For i = 0 To Password_len - 1
Password(i) = Asc(Mid(Text1.Text, i + 1, 1))
Next
If strFileName = "" Then
Exit Sub
End If
Open strFileName For Binary As #1
ReDim Databuff(LOF(1))
Get #1, , Databuff
Close #1
ReDim Addbuff(UBound(Databuff)) As Byte
For i = 0 To UBound(Databuff)
If j >= Password_len Then
j = 0
Else
j = j + 1
End If
Addbuff(i) = Databuff(i) Xor Password(j)
Next
Open strFileName For Binary As #1
Put #1, , Addbuff
Close #1
A = A + 1
WritePrivateProfileString "加密", "密码" + A, strFileName + "_" + Code, App.Path + "\" + "code.CID"
WritePrivateProfileString "加密", "记数", A, App.Path + "\" + "code.CID"
Text1.Text = ""
Else
Text1.Text = MsgBox("密码错误!", 16, "错误")
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
strFileName = Dir1.Path
If Right$(strFileName, 1) <> "\" Then
strFileName = strFileName + "\" + File1.FileName
Else
strFileName = strFileName + File1.FileName
End If
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
strFileName = Dir1.Path
If Right$(strFileName, 1) <> "\" Then
strFileName = strFileName + "\" + File1.FileName
Else
strFileName = strFileName + File1.FileName
End If
Open strFileName For Binary As #1
ReDim Databuff(LOF(1))
Get #1, , Databuff
Close #1
End Sub
Private Sub Form_Load()
Dim Length As Long
Dim S As String
S = String(1024, 0)
Length = GetPrivateProfileString("加密", "记数", "000", S, Len(S), App.Path + "\" + "code.CID")
A = Val(Left(S, Length))
End Sub
加密/解密的,还不错.
不过,无法对FLASH生成的EXE文件加密Top
4 楼luanjiajia(抵制日货,从我做起)回复于 2002-01-25 12:28:24 得分 5
Private Sub Command1_Click()
Dim bytI As Byte
Dim lngI As Long
Dim intI As Integer
Dim bytMid() As Byte
Open "d:\test.txt" For Binary As #1 '要加密或解密的文件 这一句打开文件
Open "d:\test1.txt" For Binary As #2 '要加密或解密后的文件
lngI = LOF(1)
ReDim bytMid(LOF(1) - 1)
For intI = 0 To LOF(1) - 1
Get #1, intI + 1, bytI
bytMid(intI) = Not bytI
Next
Put #2, 1, bytMid
Close #1
Close #2
MsgBox "加密成功"
End Sub
Top
5 楼luanjiajia(抵制日货,从我做起)回复于 2002-01-25 12:28:40 得分 0
不过你的分也太少了
Top
6 楼PM0115(C++ing)回复于 2002-01-26 12:44:20 得分 0
很抱歉!分的确太少了,但我也没有办法,我只是个莱鸟,
还请大家多多关照!,谢谢了,各位!Top




