|
-
Sep 18th, 2004, 05:32 AM
#1
Thread Starter
Member
String Problems!
Hi.
I am working in an Encrypter/Decrypter.
I want the encryption to be saved in a file.
I do that, but when I open it, the string is not
the real one. There are unicode changes to
the string, like:
What is more strange, my other encryption is
based in numbers only, I experience error with
that too.
I've also tried using .rtf, but no help.
Please can anyone suggest any way I can save
the string to a file and when open it again, it
will be not altered as I said above :S .
Code I use to load the string to rich text box in my app
is:
Code:
Public Function ReadFileContents(FileFullPath As String) As String
On Error Resume Next
Dim iFileNumber As Integer
Dim sAns As String
If Dir(FileFullPath) = "" Then Exit Function
iFileNumber = FreeFile
Open FileFullPath For Input As #iFileNumber
sAns = Input(LOF(iFileNumber), #iFileNumber)
Close #iFileNumber
If sAns = "" Then
MsgBox "Text file is empty!", vbInformation, "Encrypted Brain 2.0"
Else
If ovr.Value = 1 Then
txtDecrypt.Text = sAns
Else
txtDecrypt.Text = txtDecrypt.Text & sAns
End If
End If
End Function
-
Sep 18th, 2004, 06:07 AM
#2
If you have encrypted the text in to the saved file, shouldn't you decrypt the data before putting it to the textbox?
-
Sep 18th, 2004, 10:40 AM
#3
Thread Starter
Member
That is done automatically. When I open saved file, I decrypt and then put it to textbox. But that decryption is not the one I expect to come. It's altered with some unicode chars.
I am also sure this is not wrong with my encryption/decryption, it's simply all about string swinging from text box to saved file and saved file to text box.
If I decrypt the same text from the textbox field, so not getting it from saved file, it works.
But all problem is with "transfering" that string FROM saved file, to textbox the ORIGINAL WAY!
Might there be any way I can save the text, wich would not alter it. I'm mostly confused at numbers. Why it happens to numbers :| when they're not unicode!
Thnx, Please help !
Last edited by BassReFLeX; Sep 18th, 2004 at 10:43 AM.
www.bassreflex.biz
-
Sep 18th, 2004, 11:49 AM
#4
Well, then there was no point in the code you submitted, because it only reads the full file and then shows it in a textbox, without decrypting it.
To make it clearer for me:
string -> encrypt -> decrypt -> string
works perfect. But:
string -> encrypt -> save -> open -> decrypt -> string
does not. Which indicated you have an error in the code you use to save the file.
-
Sep 18th, 2004, 01:10 PM
#5
are you saving it and reading it as BINARY?
try saving text and then reading it without the encryption to test.
Last edited by dglienna; Sep 19th, 2004 at 12:25 AM.
-
Sep 19th, 2004, 05:33 AM
#6
Thread Starter
Member
Yeh I am saving it in binary. But not reading it :S
Merri I don't really understand you.
I MUST save encrypted text.
string -> encrypt -> decrypt.. is not what I want.
I need the encrypted string to be saved then later viewed and decrypted if needed.
string -> encrypt -> decrypt .. just encrypts and decrypt and nothing happens. The point is to save the encrypted text and decrypt it whenever you want.
-
Sep 19th, 2004, 07:39 AM
#7
Bass, the thing was just some information I wanted to confirm, meaning: if you don't save and you decrypt the data, it decrypts fine. If you save encrypted and then load it and decrypt, it doesn't work. Anyways: if you save in binary, you must also load it in binary. Thus:
VB Code:
Dim iFileNumber As Integer
Dim sAns() As Byte
If Dir(FileFullPath) = "" Then Exit Function
iFileNumber = FreeFile
Open FileFullPath For Binary Access Read As #iFileNumber
ReDim sAns(LOF(iFileNumber) - 1)
Get #iFileNumber, , sAns
Close #iFileNumber
Then decrypt it. If you have to pass it as a string, then use CStr(sAns) when you pass the string to decryption function. If you just need to pass it to a a textbox, txtDecrypt.Text = sAns works fine. If you need to check if the array is empty, If (Not sAns) = True Then array is empty.
-
Sep 19th, 2004, 12:31 PM
#8
does is work if you read it as binary? it should work if you wrote it as binary. if not, skip the encryption to make sure you write what you mean to.
-
Sep 19th, 2004, 03:06 PM
#9
Thread Starter
Member
I use txtDecrypt.text = sAns, and all I get is a bunch of ??????????????????? instead of numbers. It's all messed up now :/.
Why does it have to be so hard to read some file the way I saved.
code to save:
Code:
Open FileName & ".rtf" For Binary Access Write As #1
Put #1, , data
Put #1, , " "
Close #1
code to read:
Code:
Public Function ReadFileContents(FileFullPath As String) As String
Dim iFileNumber As Integer
Dim sAns() As Byte
If Dir(FileFullPath) = "" Then Exit Function
iFileNumber = FreeFile
Open FileFullPath For Binary Access Read As #iFileNumber
ReDim sAns(LOF(iFileNumber) - 1)
Get #iFileNumber, , sAns
Close #iFileNumber
If (Not sAns) = True Then
MsgBox "Text file is empty!", vbInformation, "app"
Else
txtDecrypt.Text = sAns
End If
End Function
Last edited by BassReFLeX; Sep 19th, 2004 at 03:10 PM.
www.bassreflex.biz
-
Sep 19th, 2004, 03:25 PM
#10
Code:
If Dir(FileFullPath) = "" Then Exit Function
iFileNumber = FreeFile
Open FileFullPath For Binary Access Read As #iFileNumber
ReDim sAns As Byte
Get #iFileNumber, , sAns
Close #iFileNumber
i would not use binary for the read or the write.
if it's encrypted, it can't be read, right?
Last edited by dglienna; Sep 19th, 2004 at 03:30 PM.
-
Sep 19th, 2004, 03:32 PM
#11
Thread Starter
Member
Yes it's encryted, and that encryption is ONLY numbers. Numbers musn't problem with that, they're simple ascii why should they?
As for binary use, the saved text is exactcly what I want. So when I save it, I open savedfile.rtf myself, I see there is the encryption with numbers and stuff and it's ok. But when I use code to open it and put it to textbox for me, I get ???????? :| .
thnx for your effort, but really, I face strange programming moments everytime I run VB6.
-
Sep 19th, 2004, 04:28 PM
#12
Oops. I forgot one thing 
VB Code:
txtDecrypt.Text = StrConv(sAns, vbUnicode)
Any better?
-
Sep 20th, 2004, 08:55 AM
#13
Thread Starter
Member
At last!!!!!!
Biggest thnx to Merri, thank you all!
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
|