Results 1 to 3 of 3

Thread: [RESOLVED] [2008] encrypt file then save and then be able to decrypt file then open

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Resolved [RESOLVED] [2008] encrypt file then save and then be able to decrypt file then open

    Hello,

    I have a button on my form that encypts the file and then saves it using a save dialog box.it uses a list box. i have never worked with listboxes before so i dont know what to save... should i save listbox1.text or listbox1.items or what? Then i want to be able to decrypt and then open the file. so what should i set the opened file to listbox1.text or listbox1.items or what?

    save code
    Code:
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim objwriter As StreamWriter
            Dim strdata As String
            'encrypter/decrypter
            '>>> validation
            
            strdata = MessageTransposition(ListBox1.Text, True)
            Try
                SaveFileDialog1.ShowDialog()
                SaveFileDialog1.Filter = "Dansoft Media Player (*.DMP)|*.DMP|All files (*.*)|*.*"
                objwriter = New StreamWriter(SaveFileDialog1.FileName)
    
                objwriter.Write(strdata)
                objwriter.Close()
    
    
            Catch Ex As Exception
                MsgBox(Ex.Message)
            End Try
    
        End Sub
    decrypt code

    Code:
    Private Function MessageTransposition(ByVal StrDataIn As String, ByVal ED As Boolean) As String
    
    
    
            Dim IndR As Integer
            Dim IndC As Integer
    
            IndR = 3
            IndC = 4
            '>>> create the array
            Dim DataArray(IndR, IndC) As String
            Dim i, j As Integer
            Dim r, c As Integer
            Dim StrOut As String
            StrOut = ""
            i = 1
            '>>> loop to total length
            While i <= StrDataIn.Length
    
                '>>> clear the array
                For r = 0 To IndR
                    For c = 0 To IndC
                        DataArray(r, c) = Chr(1)
                    Next
                Next
    
                '>>> check the loop last postion
                Dim LastPos As Integer
                If i + (IndR * IndC) - 1 <= StrDataIn.Length Then
                    LastPos = i + (IndR * IndC) - 1
                Else
                    LastPos = StrDataIn.Length
                End If
    
                '>>> store strdatain into array character by character
                '>>> initial the array indexer
                r = 0
                c = 0
                For j = i To LastPos
    
    
    
                    DataArray(r, c) = Mid(StrDataIn, j, 1)
    
    
                    c = c + 1
    
    
                    '>>> reset the array indexer
                    If r > IndR - 1 Then
                        r = 0
                        c = 0
                    End If
                    If c > IndC - 1 Then
                        c = 0
                        r = r + 1
                    End If
                Next
    
                '>>> add array value to string coulumn nad row wise
                If ED = True Then
                    For c = 0 To IndC - 1
                        For r = 0 To IndR - 1
                            StrOut = StrOut & DataArray(r, c)
                        Next
                    Next
                Else
                    '>>> decrypt logics
                    Dim StrTemp As String
                    StrTemp = ""
                    Dim p, p1 As Integer
                    p = 1
                    p1 = 1
                    For r = 0 To IndR - 1
                        For c = 0 To IndC - 1
                            StrTemp = StrTemp & DataArray(r, c)
                        Next
                    Next
    
                    While p <= StrTemp.Length
                        '>>> replace array filling character
    
                        
                        StrOut = StrOut & Replace(Mid(StrTemp, p1, 1), Chr(1), "")
    
    
    
                        p = p + 1
    
                        '>>> increment position by row
                        p1 = p1 + IndR
                        If p1 > StrTemp.Length Then
                            p1 = p1 - StrTemp.Length + 1
                        End If
                    End While
                End If
                i = i + IndR * IndC
            End While
    
            MessageTransposition = StrOut
    
    
        End Function
    open code

    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            OpenFileDialog1.ShowDialog()
            OpenFileDialog1.Filter = "Dansoft Media Player (*.DMP)|*.DMP|All files (*.*)|*.*"
    
            ListBox1.Items.Add(MessageTransposition(OpenFileDialog1.FileName, False))
        End Sub
    that is all the code fro saving/opening/encrypting/decypting. if you know anything about this just speak up any heal is welcome.

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Re: [2008] encrypt file then save and then be able to decrypt file then open

    I assume the file content is what you want listed in the listbox. Since I have no idea how you seperate your data, the only advice I can give you is that you use the listbox Items list Add method(ListBox1.Items.Add(ListItem)), and input what you want displayed.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] encrypt file then save and then be able to decrypt file then open

    sorry i figured this out on my own forgot to mark as resolved

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