|
-
Jun 6th, 2001, 02:30 PM
#1
Thread Starter
Fanatic Member
File decryption
I have a program the encrypts text files so they aren't readbale and then i need a different program to open the file and decrypt it. Below is the decrypt code and open code all as one. It gives me and error with this code:
decrypted$ = decrypted$ & newstr which is part of below code
it highlights the second decrypted$
Type-declaration charcter does not match declared data type
any help on why this is happening and what to do about it?
Sub frmMainFileOpenAs(Optional ByVal sFile As String)
On Error GoTo Exit_Sub
If Len(sFile) Then GoTo OpenFile
With frmMain
With .CommonDialog1
.CancelError = True
.DialogTitle = "File Save"
.Filter = "EDF(*.EDF)|*.EDF"
.ShowOpen
End With
If Len(.CommonDialog1.FileName) = 0 Then Exit Sub
sFile = .CommonDialog1.FileName
End With
OpenFile:
With frmMain
.listURL.Clear
.bDisableClickEvent = True
Open sFile For Input As #1
Dim strLine As String
Dim i As Long
Dim tmpstr As String
Dim pass$
Dim letter
Dim encstr
Dim newstr
Dim decrypted
Do While Not EOF(1)
Line Input #1, strLine
.Text1 = strLine
pass$ = Len(frmMain.password.Text) 'this is the exact same For the Encrypt Function
tmpstr = Len(frmMain.Text1.Text) 'the only difference is that instead of adding the lenght of password.text
'it is subtracted
If tmpstr = "0" Then
MsgBox ("You must first Type In something To Decrypt")
Exit Sub
End If
For i = 1 To tmpstr
letter = mID$(frmMain.Text1.Text, i, 1)
encstr = Asc(letter) - pass$
newstr = Chr$(encstr)
decrypted$ = decrypted$ & newstr
Next i
frmMain.Text1.Text = decrypted$
frmMain.Text1 = strLine
If i = 0 Then
.txtSavePath = Trim(strLine)
Else
.listURL.AddItem Trim(strLine)
.ListName.AddItem mID(strLine, InStrRev(strLine, "/") + 1)
End If
i = i + 1
Loop
Close_File:
Close #1
.bDisableClickEvent = False
.ShowSatus
.ChangeSaveFileName
Exit_Sub:
End With
End Subdecrypted$ = decrypted$ & newstr
-
Jun 6th, 2001, 02:46 PM
#2
Change this line:
Dim decrypted
..to this:
Dim decrypted$
..or this:
Dim decrypted As String
..or you can change "decrypted$" wherever it is in your code to just "decrypted".
-
Jun 6th, 2001, 03:04 PM
#3
Thread Starter
Fanatic Member
umm yeah stupid me i forgot that $ sign but i have another question! It doesn't decrypt the file! Above is the decrypt code and below this is the encrypt code. Is it becuase i set up the code that tell is where to put the decrypted text?
Private Sub cmdEncrypt_Click()
Dim sve As String
Dim pass$
Dim tempstr As String
Dim letter
Dim encstr As String
Dim encrypted$
Dim newstr As String
pass$ = Len(password.Text) 'the number you shift Each letter To encrypt
tmpstr = Len(Text1.Text)
If tmpstr = "0" Then
MsgBox ("You must first Type In something To Encrypt") 'You can't encrypt nothing
Exit Sub
End If
For i = 1 To tmpstr
letter = Mid$(Text1.Text, i, 1) 'takes the ascii value and adds the length of the password To it
encstr = Asc(letter) + pass$
newstr = Chr$(encstr) 'changes ascii value To a character
encrypted$ = encrypted$ & newstr 'puts all the encrypted characters together
Next i
Text1.Text = encrypted$ 'puts the encrypted String in text box
CommonDialog1.Filter = "EDF files (*.edf)|*.edf"
CommonDialog1.ShowSave
Form1.Caption = "EDF Save" & CommonDialog1.FileTitle
sve = Text1.Text
Open CommonDialog1.FileName For Output As #1
Print #1, sve
Close #1
End Sub
-
Jun 6th, 2001, 03:48 PM
#4
Thread Starter
Fanatic Member
Just wanted to say that i have solved my problem!
Last edited by stickman373; Jun 6th, 2001 at 04:06 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|