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 codedecrypt codeCode: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
open codeCode: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
that is all the code fro saving/opening/encrypting/decypting. if you know anything about this just speak up any heal is welcome.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




Reply With Quote