Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda Project 2 Supplement

Similar presentations


Presentation on theme: "Agenda Project 2 Supplement"— Presentation transcript:

1 Agenda Project 2 Supplement
Similar to your project 2, the following sample code can be used to help you get started with the project. It incorporates previous topics we introduced such as string manipulation, file I/O, looping, the ASCII character set and arrays.

2 (Read in the key values and store in an array)
‘Read in the key values and store them in an array 'Define a 4 element array Dim key(3) As Integer ' Private Sub Form1_Load(...) Handles MyBase.Load 'Load key and keyvalue when Form1 loads Dim KeyNum, i As Integer Dim KeyString As String 'Find key number Dim kn as IO.StreamReader=IO.File.OpenText("A:/KeyNum.txt") KeyNum = kn.ReadLine kn.Close() 'Display in a textbox txtKeyNum.Text = keyNum

3 (Read in the key values and store in an array) - Continued
'Open the Keys.text file Dim ky as IO.StreamReader=IO.File.OpenText("A:/Keys.txt") For i = 1 To KeyNum KeyString = ky.ReadLine Next txtKey.Text = KeyString ‘Display in a textbox ky.Close() For i = 0 To 3 key(i) = KeyString.SubString(i, 1) End Sub

4 (Get Cleartext & Character Shift)
'Get the cleartext message Dim Message As String Dim sf as IO.StreamReader=IO.File.OpenText("A:/ClearOut.txt") Do While sf.Peek <> -1 Message = sf.ReadLine txtOne.Text = txtOne.Text & Message Loop sf.Close() ' ‘Simple Character Shifting Dim i, KeyDigit, CharASCII As Integer Dim CurrentChar, CharOutput As String For i = 0 To txtOne.Text.Length - 1 CurrentChar = txtOne.Text.SubString(i, 1) If Asc(CurrentChar) = 13 Then txtOne.Text = txtOne.Text + Chr(13)

5 (Character Shift) –Continued from Previous Slide
ElseIf Asc(CurrentChar) = 10 Then txtOne.Text = txtOne.Text + Chr(10) Else KeyDigit = i Mod 4 CharASCII = Asc(CurrentChar) + key(KeyDigit) If CharASCII > 126 Then CharASCII = CharASCII - 95 End If txtTwo.Text = txtTwo.Text + Chr(CharASCII) Next


Download ppt "Agenda Project 2 Supplement"

Similar presentations


Ads by Google