Results 1 to 13 of 13

Thread: String Problems!

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    35

    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
    www.bassreflex.biz

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    If you have encrypted the text in to the saved file, shouldn't you decrypt the data before putting it to the textbox?

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    35
    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

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    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.

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    35
    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.
    www.bassreflex.biz

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    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:
    1. Dim iFileNumber As Integer
    2. Dim sAns() As Byte
    3.  
    4. If Dir(FileFullPath) = "" Then Exit Function
    5. iFileNumber = FreeFile
    6. Open FileFullPath For Binary Access Read As #iFileNumber
    7. ReDim sAns(LOF(iFileNumber) - 1)
    8. Get #iFileNumber, , sAns
    9. 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.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    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.

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    35
    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

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    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.

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    35
    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.
    www.bassreflex.biz

  12. #12
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Oops. I forgot one thing

    VB Code:
    1. txtDecrypt.Text = StrConv(sAns, vbUnicode)

    Any better?

  13. #13

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    35
    At last!!!!!!

    Biggest thnx to Merri, thank you all!
    www.bassreflex.biz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width