Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 13 Exploring Text Files and String Processing 341


Run the Xor Encryption program now to see how the Xor operator works in the note-taking
utility you’ve been building.

Encrypt text with the Xor operator


  1. Close the Encrypt Text project, and then open the Xor Encryption project in the
    C:\Vb10sbs\Chap13\Xor Encryption folder.

  2. Click the Start Debugging button to run the program.

  3. Type the following text (or some of your own) in the encrypted text file:


Rothair’s Edict (Lombard Italy, c. 643) 296.

On Stealing Grapes. He who takes more than three grapes from another man’s
vine shall pay six soldi as compensation. He who takes less than three shall bear
no guilt.


  1. On the File menu, click the Save Encrypted File As command, and then save the file in
    the C:\Vb10sbs\Chap13 folder with the name Oldlaws.txt.
    The program prompts you for a secret encryption code (a number) that will be used to
    encrypt the file and decrypt it later. (Take note—you’ll need to remember this code to
    decode the file .)

  2. Type 500 , or another numeric code, and then press ENTER.


Visual Basic encrypts the text by using the Xor operator and then stores it on disk as a
series of numbers. You won’t see any change on your screen, but rest assured that the
program created an encrypted file on disk. (You can verify this with a word processor
or a text editor .)


  1. Click the Close command on the program’s File menu to clear the text in the text box.


Now you’ll restore the encrypted file.


  1. On the File menu, click the Open Encrypted File command.

  2. Open the C:\Vb10sbs\Chap13 folder, and then double-click the Oldlaws .txt file.

  3. Type 500 (or the encryption code that you specified, if different) in the Xor Encryption
    dialog box when it appears, and then click OK.

Free download pdf