Vernam Cipher User Manual
Vernam Cipher User Manual
Computer Security (DDC 3342) Semester 7 Sesi 2012/2013 Project Vernam Chiper
Page 1
Computer Security
Content Coding Pseudocode User manual Flow Chart Executable program .. .. .. ..
Page 2
Computer Security
Coding
Public Class Form1 Dim CodeKey As String = "82938472" Private Sub PlainTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlainTextBox.TextChanged CipherRichTextBox.Clear() Dim DataIn As String = PlainTextBox.Text Dim Dim Dim Dim Dim Dim lonDataPtr As Long strDataOut As String temp As Integer tempstring As String intXOrValue1 As Integer intXOrValue2 As Integer
For lonDataPtr = 1 To Len(DataIn) 'The first value to be XOr-ed comes from the data to be encrypted intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1)) 'The second value comes from the code key intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1)) temp = (intXOrValue1 Xor intXOrValue2) tempstring = Hex(temp) 'If Len(tempstring) = 1 Then tempstring = "0" & tempstring tempstring = Convert.ToChar(Convert.ToUInt32(Integer.Parse(temp))) strDataOut = strDataOut + tempstring Debug.WriteLine(strDataOut) Next lonDataPtr CipherRichTextBox.Text = strDataOut End Sub
Private Sub CipherDRichTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CipherDRichTextBox.TextChanged PlainTRichTextBox2.Clear() Dim DataIn As String = CipherDRichTextBox.Text Dim Dim Dim Dim Dim Dim lonDataPtr As Long strDataOut As String temp As Integer tempstring As String intXOrValue1 As Integer intXOrValue2 As Integer
For lonDataPtr = 1 To Len(DataIn) 'The first value to be XOr-ed comes from the data to be encrypted intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1)) 'The second value comes from the code key intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1)) temp = (intXOrValue1 Xor intXOrValue2) tempstring = Hex(temp)
Page 3
Computer Security
'If Len(tempstring) = 1 Then tempstring = "0" & tempstring tempstring = Convert.ToChar(Convert.ToUInt32(Integer.Parse(temp))) strDataOut = strDataOut + tempstring Debug.WriteLine(strDataOut) Next lonDataPtr PlainTRichTextBox2.Text = strDataOut End Sub End Class
Page 4
Computer Security
Pseudocode
1. All the code can be executed automatically when inserting a plain text to the text box on the interface. For example I love Computer Security. 2.
We can read the entire plain text as one long string. For getting out each character of the plain text from the string we can use a pointer
Dim DataIn As String = PlainTextBox.Text Dim lonDataPtr As Long Dim strDataOut As String
3.
For getting out each character of the plain text from the string we can use a set up variables for storing the ASCII value of a character as well as each integer that will represent the cipher text and also using exclusive OR.
Dim Dim Dim Dim temp As Integer tempstring As String intXOrValue1 As Integer intXOrValue2 As Integer intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1)) 'The second value comes from the code key intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
4. Next we prepare to write the cipher text into the file cipher.
Private Sub PlainTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlainTextBox.TextChanged CipherRichTextBox.Clear()
5. Finally, we employ for loop to call the function for encrypting the plain text. It is the same method for decrypting.
For lonDataPtr = 1 To Len(DataIn) 'The first value to be XOr-ed comes from the data to be encrypted intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1)) 'The second value comes from the code key intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1)) temp = (intXOrValue1 Xor intXOrValue2) tempstring = Hex(temp) 'If Len(tempstring) = 1 Then tempstring = "0" & tempstring tempstring = Convert.ToChar(Convert.ToUInt32(Integer.Parse(temp))) strDataOut = strDataOut + tempstring Debug.WriteLine(strDataOut) Next lonDataPtr
Computer Security
1. Insert a plain text to the text box. For an Example I Love Pc Security. 2. Then the text will automatically encrypt and appear to the encrypted text box at the bottom. 3. Repeat step 1 for decrypted plain text.
Encrypted text
Decrypted text
Computer Security
Yes
Yes
Page 7