Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

University of Sumer

College of Computer Science and Information

Technology

Dept. Computer Science/Fourth Class

Course Title

Laboratory of Computer Security (1)

" Lecturer "


Dr: Ali Hussein Hassan
Ahmed Basim

1
Encryption and Decryption for Simple vigenere Cipher Method

Theory

Simple Vigenere Cipher


It is the same to simple vigenere Cipher. But to complete key, we must add the
letters from plaintext as the example below.
Ex: Use Simple Vigenere Cipher to encrypt the plaintext “Computer Science”
And key “second”
Sol:
P=computerscience
2 14 12 15 20 19 4 17 18 2 8 4 13 2 4
K= s e c o n d c o m p u t e r s
18 4 2 14 13 3 2 14 12 15 20 19 4 17 18
So,
Using the same encryption eq. 𝐶𝑖 = (𝑃𝑖 + 𝐾𝑖)𝑚𝑜𝑑 26
𝐶1 = (𝑃1 + 𝐾1) 𝑚𝑜𝑑 𝑛 → 𝐶1 = (3 + 12)𝑚𝑜𝑑26
𝐶1 = 𝟐𝟎 𝑖𝑠 𝑼
𝐶2 = 𝟏𝟖 𝑚𝑜𝑑26 𝐶2 = 18 𝑖𝑠 𝑺
𝐶3 = 𝟏𝟒 𝑚𝑜𝑑26 𝐶3 = 𝟏𝟒 𝑖𝑠 𝑶
𝐶4 = 𝟐𝟗 𝑚𝑜𝑑26 𝐶4 = 𝟑 𝑖𝑠 𝑫
𝐶5 = 𝟑𝟑 𝑚𝑜𝑑26 𝐶5 = 𝟕 𝑖𝑠 𝑯
𝐶6 = 𝟐𝟐 𝑚𝑜𝑑26 𝐶6 = 𝟐𝟐 𝑖𝑠 𝑾
𝐶7 = 𝟔 𝑚𝑜𝑑26 𝐶7 = 𝟔 𝑖𝑠 𝑮
𝐶8 = 𝟑𝟏 𝑚𝑜𝑑26 𝐶8 = 𝟓 𝑖𝑠 𝑭
𝐶9 = 𝟑𝟎 𝑚𝑜𝑑26 𝐶9 = 𝟒 𝑖𝑠 𝑬
𝐶10 = 𝟏𝟕 𝑚𝑜𝑑26 𝐶10 = 𝟏𝟕 𝑖𝑠 𝑹
𝐶11 = 𝟐𝟖 𝑚𝑜𝑑26 𝐶11 = 𝟐 𝑖𝑠 𝑪
𝐶12 = 𝟐𝟑 𝑚𝑜𝑑26 𝐶12 = 𝟐𝟑 𝑖𝑠 𝑿

2
Fig.: Simple Vigenere Cipher method Components.

3
codes for Encryption Simple Vigenere Cipher

Public Class Form1


Dim t1, t2, i, a, x, x1, x2, y, z, k, k2 As Integer
Dim sum = "", m, kk, c, z1 As String

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


t1 = Len(TextBox1.Text)
t2 = Len(TextBox2.Text)
If t2 < t1 Then
x1 = t1 - t2
For i = 1 To x1
z1 = Mid(TextBox1.Text, i, 1)
TextBox2.Text = TextBox2.Text + z1

Next
End If

For i = 1 To t1
m = Mid(TextBox1.Text, i, 1)
a = Asc(m)
kk = Mid(TextBox2.Text, i, 1)
k = Asc(kk)
If (a >= 65) And (a <= 90) Then
k2 = k - 65
Else
k2 = k - 97

End If Encryption
If (a >= 65) And (a <= 90) Then
x = a - 65
y = x + k2
z = y Mod 26
x2 = z + 65
Else
x = a - 97
y = x + k2
z = y Mod 26
x2 = z + 97
End If
c = Chr(x2)
sum = sum + c

Next
TextBox3.Text = sum

End Sub

Fig2 codes for Encryption Simple Vigenere Cipher

4
For i = 1 To Len(TextBox3.Text)
m = Mid(TextBox3.Text, i, 1)
a = Asc(m)
kk = Mid(TextBox2.Text, i, 1)
k = Asc(kk)
If (k > 65) And (k <= 90) Then
k2 = k - 65
Else
k2 = k - 97
End If
If (a >= 65) And (a <= 90) Then
x3 = a - 65

If (x3 < k2) Then


x = 26 + x3
Else
x = x3
Decryption
End If
y = x - k2
z = y Mod 26
x2 = z + 65
Else
x3 = a - 97
If (x3 < k2) Then
x = 26 + x3

Else
x = x3
End If
y = x - k2
z = y Mod 26
x2 = z + 97
End If
c = Chr(x2)
sum = sum + c
Next
TextBox4.Text = sum
End Sub

End Class

Fig 4 codes for Decryption Simple Vigenere Cipher

5
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click

TextBox1.Clear()
Clear
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click

End
end
End Sub

Fig codes for clear and end

You might also like