Chapter 13 Exploring Text Files and String Processing 343
MsgBox("An error occurred." & vbCrLf & ex.Message)
Finally
If StreamToWrite IsNot Nothing Then
StreamToWrite.Close()
End If
End Try
End If
In the Write method the Xor operator is used to convert each letter in the text box
to a numeric code, which is then saved to disk one number at time. The numbers are
separated with spaces.
The final result of this encryption is no longer textual, but numeric—guaranteed to bewilder
even the nosiest snooper. For example, the following screen shot shows the encrypted file
produced by the preceding encryption routine, displayed in Notepad. (I’ve enabled Word
Wrap so that you can see all the code .)
The mnuOpenItem_Click event procedure contains the following program statements.
(Again, pay particular attention to the lines in bold .)
Dim AllText As String
Dim i As Short
Dim ch As Char
Dim strCode As String
Dim Code, Number As Short
Dim Numbers() As String
Dim Decrypt As String = ""
OpenFileDialog1.Filter = "Text files (*.txt)|*.txt"
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then 'display Open dialog box
Try 'open file and trap any errors using handler
strCode = InputBox("Enter Encryption Code")
If strCode = "" Then Exit Sub 'if cancel clicked