Encryption

cdoverlaw

Well-known member
Joined
Oct 11, 2003
Messages
146
Hi
Currently i am have an encryption procedure like this

Code:
Dim letter As Char
        Dim strCode As String
        Dim i, charsInFile, Code As Short

        SaveFileDialog1.Filter = "Text files (*.txt)|*.txt"
        SaveFileDialog1.ShowDialog()
        If SaveFileDialog1.FileName <> "" Then
            strCode = InputBox("Enter Encryption Code")
            If strCode = "" Then Exit Sub if cancel clicked
            save text with encryption scheme
            Code = CShort(strCode)
            charsInFile = txtNote.Text.Length
            FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
            For i = 0 To charsInFile - 1
                letter = txtNote.Text.Substring(i, 1)
                convert to number w/ Asc, then use Xor to encrypt
                Print(1, Asc(letter) Xor Code) and save in file
            Next
            FileClose(1)
            mnuCloseItem.Enabled = True
        End If

I want to convert it so that it saves the file as encryptioncode.txt encrypted with a code of my choice (i will just replace InputBox("Enter Encryption Code") with my encryption code number) to the folder where my program is,
The box where the data for the txt file is, is called txtEncryptPass

I also want to open this file (and decrypt it) when program is opened in the load event, i currently have this code to open files using this encryption method

Code:
Dim ch As Char
        Dim strCode As String
        Dim Code, Number As Short
        Dim Decrypt As String = ""

        OpenFileDialog1.Filter = "Text files (*.TXT)|*.TXT"
        OpenFileDialog1.ShowDialog() display Open dialog box
        If OpenFileDialog1.FileName <> "" Then
            Try open file and trap any errors using handler
                strCode = InputBox("Enter Encryption Code")
                If strCode = "" Then Exit Sub if cancel clicked
                Code = CShort(strCode)
                FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
                Do Until EOF(1) read lines from file
                    Input(1, Number) read encrypted numbers
                    ch = Chr(Number Xor Code) convert with Xor
                    Decrypt = Decrypt & ch and build string
                Loop
                txtNote.Text = Decrypt then display converted string
                lblNote.Text = OpenFileDialog1.FileName
                txtNote.Select(1, 0)   remove text selection
                txtNote.Enabled = True allow text cursor
                mnuCloseItem.Enabled = True  enable Close command
                mnuOpenItem.Enabled = False  disable Open command
            Catch
                MsgBox("Error opening file.")
            Finally
                FileClose(1) close file
            End Try
        End If

Thank you for your help,

Jonathan
 
Back
Top