Analisis Perbandingan Metode Playfair Cipher dan Elgamal pada Kriptografi Citra

62

Listing Program Playfair Elgamal
Form1 :
Public Class Form1
Public Shared Kunci As Integer(,) = New Integer(16, 16) {}
Public Shared strKunci As String
Public Shared Sub getKunci(ByVal z0 As Integer)
strKunci = ""
Dim z() As Integer = New Integer(256) {}
Dim sum As Integer = 0
z(0) = z0
For i = 1 To 255
z(i) = (21 * z(i - 1) + 173) Mod 256
Next
For i = 0 To 15
For j = 0 To 15
Kunci(i, j) = z(sum)
sum += 1
strKunci += " " + Kunci(i, j).ToString() + Chr(9)
Next

Next
End Sub
Private Sub EnkripsiToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles EnkripsiToolStripMenuItem.Click
Dim frm2 As New Form2()
frm2.ShowDialog()
End Sub
Private Sub DekripsiToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DekripsiToolStripMenuItem.Click
If (MessageBox.Show("Anda akan masuk ke Form Dekripsi. Apakah yakin
Dekripsi Gambar tanpa Enkripsi terlebih dulu?", "Warning",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes) Then
Dim frm3 As New Form3()
frm3.ShowDialog()
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub

End Class

Universitas Sumatera Utara

63

Form2 :
Public Class Form2
Dim cipher1, cipher2 As Integer
Dim g, k As Integer
Public x, p As Integer
Dim y, b As BigInteger
Public a As BigInteger
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog()
Dim path As String
openFileDialog1.Filter = "bmp Files|*.bmp|png Files|*.png"
openFileDialog1.FileName = "*.bmp"
If (openFileDialog1.ShowDialog() = DialogResult.OK) Then

Dim gbr_Asli As New Bitmap(openFileDialog1.FileName)
If (gbr_Asli.Width Mod 2 = 1) Then
MessageBox.Show("Lebar Pixel Gambar tidak bisa Ganjil.")
Exit Sub
End If
PictureBox1.Image = gbr_Asli
LCitraAsli.Text = gbr_Asli.Width
PCitraAsli.Text = gbr_Asli.Height
path = System.IO.Path.GetFullPath(openFileDialog1.FileName)
Dim fileinfo As New System.IO.FileInfo(path)
Dim size As Double = fileinfo.Length / 1024
SizeCitraAsli.Text = (Math.Round(size, 1)).ToString()
NamaCitra.Text =
System.IO.Path.GetFileName(openFileDialog1.FileName)
End If
End Sub
Private Sub enkripPlayFair(ByVal bigram As Integer(), ByVal Kunci As
Integer(,))
Dim limit As Boolean = False
Dim bigramx As Integer() = New Integer(2) {}

Dim bigramy As Integer() = New Integer(2) {}
For x = 0 To 1
For i = 0 To 15
For j = 0 To 15
If (bigram(x) = Kunci(i, j)) Then
bigramx(x) = i
bigramy(x) = j
limit = True
If (limit = True And x = 2) Then
Exit For
End If
End If
Next
If (limit = True And x = 2) Then
Exit For
End If
Next
Next
If (bigramx(0) = bigramx(1)) Then
If (bigramy(0) = 15) Then


Universitas Sumatera Utara

64

cipher1 = Kunci(bigramx(0), 0)
cipher2 = Kunci(bigramx(1), bigramy(1) + 1)
ElseIf (bigramy(1) = 15) Then
cipher1 = Kunci(bigramx(0), bigramy(0) + 1)
cipher2 = Kunci(bigramx(1), 0)
Else
cipher1 = Kunci(bigramx(0), bigramy(0) + 1)
cipher2 = Kunci(bigramx(1), bigramy(1) + 1)
End If
ElseIf (bigramy(0) = bigramy(1)) Then
If (bigramx(0) = 15) Then
cipher1 = Kunci(0, bigramy(0))
cipher2 = Kunci(bigramx(1) + 1, bigramy(1))
ElseIf (bigramx(1) = 15) Then
cipher1 = Kunci(bigramx(0) + 1, bigramy(0))

cipher2 = Kunci(0, bigramy(1))
Else
cipher1 = Kunci(bigramx(0) + 1, bigramy(0))
cipher2 = Kunci(bigramx(1) + 1, bigramy(1))
End If
Else
cipher1 = Kunci(bigramx(0), bigramy(1))
cipher2 = Kunci(bigramx(1), bigramy(0))
End If
End Sub
Private Sub enkripsiPlayfair_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles enkripsiPlayfair.Click
If txtKunci.Text = "" Then
MessageBox.Show("Generate Kunci Playfair terlebih dulu")
txtZ0.Focus()
Exit Sub
End If
Dim
Dim
Dim

Dim
Dim
Dim
Dim
Dim

sw As New Stopwatch
gbr_Asli As Bitmap = New Bitmap(PictureBox1.Image)
gbr_Playfair As Bitmap = New Bitmap(PictureBox1.Image)
x As Integer = gbr_Asli.Width
y As Integer = gbr_Asli.Height
bigram As Integer() = New Integer(2) {}
r1, g1, b1, r2, g2, b2 As Integer
rCipher1, gCipher1, bCipher1, rCipher2, gCipher2, bCipher2 As

Integer
waktuPlayfair.Text = "Lama Proses Enkripsi : "
sw.Start()
For i = 0 To y - 1
For j = 0 To x - 1 Step 2

r1 = gbr_Asli.GetPixel(j, i).R
r2 = gbr_Asli.GetPixel(j + 1, i).R
bigram(0) = r1
bigram(1) = r2
enkripPlayFair(bigram, Form1.Kunci)
rCipher1 = cipher1
rCipher2 = cipher2
g1 = gbr_Asli.GetPixel(j, i).G
g2 = gbr_Asli.GetPixel(j + 1, i).G
bigram(0) = g1
bigram(1) = g2
enkripPlayFair(bigram, Form1.Kunci)
gCipher1 = cipher1

Universitas Sumatera Utara

65

gCipher2 = cipher2
b1 = gbr_Asli.GetPixel(j, i).B

b2 = gbr_Asli.GetPixel(j + 1, i).B
bigram(0) = b1
bigram(1) = b2
enkripPlayFair(bigram, Form1.Kunci)
bCipher1 = cipher1
bCipher2 = cipher2
gbr_Playfair.SetPixel(j, i, Color.FromArgb(255, rCipher1,
gCipher1, bCipher1))
gbr_Playfair.SetPixel(j + 1, i, Color.FromArgb(255, rCipher2,
gCipher2, bCipher2))
Next
Next
PictureBox2.Image = gbr_Playfair
LCitraPlayfair.Text = gbr_Playfair.Width
PCitraPlayfair.Text = gbr_Playfair.Height
sw.Stop()
Dim detik As Double
detik = Math.Round(sw.ElapsedMilliseconds / 1000, 3)
waktuPlayfair.Text += sw.ElapsedMilliseconds.ToString() + " ms / " +
detik.ToString() + " s"

MessageBox.Show("Proses Enkripsi telah selesai", "Enkripsi",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub SimpanPlayfair_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SimpanPlayfair.Click
Dim simpan As New SaveFileDialog()
Dim path As String
simpan.Filter = "bmp Files|*.bmp"
simpan.FileName = "*.bmp"
If (simpan.ShowDialog() = DialogResult.OK) Then
PictureBox2.Image.Save(simpan.FileName,
System.Drawing.Imaging.ImageFormat.Bmp)
NamaCitraPlayfair.Text =
System.IO.Path.GetFileName(simpan.FileName)
path = System.IO.Path.GetFullPath(simpan.FileName)
Dim fileinfo As New System.IO.FileInfo(path)
Dim size As Double = fileinfo.Length / 1024
SizeCitraPlayfair.Text = (Math.Round(size, 1)).ToString()
MessageBox.Show("Gambar telah berhasil disimpan", "Simpan",
MessageBoxButtons.OK, MessageBoxIcon.Information)

End If
End Sub
Private Sub MenuUtamaToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MenuUtamaToolStripMenuItem.Click
Me.Dispose()
End Sub
Private Sub DekripsiToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DekripsiToolStripMenuItem.Click
Dim frm3 As New Form3()
frm3.ShowDialog()
End Sub
Private Sub SimpanElgamal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SimpanElgamal.Click
Dim simpan As New SaveFileDialog()

Universitas Sumatera Utara

66

Dim path As String
simpan.Filter = "bmp Files|*.bmp"
simpan.FileName = "*.bmp"
If (simpan.ShowDialog() = DialogResult.OK) Then
PictureBox3.Image.Save(simpan.FileName,
System.Drawing.Imaging.ImageFormat.Bmp)
NamaCitraElgamal.Text = System.IO.Path.GetFileName(simpan.FileName)
path = System.IO.Path.GetFullPath(simpan.FileName)
Dim fileinfo As New System.IO.FileInfo(path)
Dim size As Double = fileinfo.Length / 1024
SizeCitraElgamal.Text = (Math.Round(size, 1)).ToString()
MessageBox.Show("Gambar telah berhasil disimpan", "Simpan",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub Generate_kunci_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Generate_kunci.Click
Dim rnd As New Random
If keyp.Text = "" Then
MessageBox.Show("Isi bilangan Prima terlebih dahulu", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
keyp.Focus()
ElseIf keyp.Text > 257 Then
MessageBox.Show("Bilangan Prima tidak bisa lebih dari 257",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
keyp.Focus()
ElseIf keyp.Text < 257 Then
MessageBox.Show("Bilangan Prima terlalu kecil, hasil dekripsi
kemungkinan akan salah", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
keyp.Focus()
ElseIf keyp.Text = 257 Then
p = Convert.ToInt32(keyp.Text)
g = rnd.Next(1, p)
x = rnd.Next(1, p)
y = BigInteger.ModPow(g, x, p)
k = rnd.Next(1, p - 2)
a = BigInteger.ModPow(g, k, p)
keyg.Text = g.ToString()
keyx.Text = x.ToString()
keyk.Text = k.ToString()
keya.Text = a.ToString()
End If
End Sub
Private Sub EnkripsiElgamal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles EnkripsiElgamal.Click
Dim m As Integer
Dim sw As New Stopwatch
Dim gbr_Asli As Bitmap = New Bitmap(PictureBox1.Image)
Dim gbr_Elgamal As Bitmap = New Bitmap(PictureBox1.Image)
Dim w As Integer = gbr_Asli.Width
Dim h As Integer = gbr_Asli.Height
Dim bR, bG, bB As Integer
If keyx.Text = "" Then
MessageBox.Show("Generate Key terlebih dahulu", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
waktuElgamal.Text = "Lama Proses Enkripsi : "

Universitas Sumatera Utara

67

sw.Start()
For i = 0 To h - 1
For j = 0 To w - 1
m = gbr_Asli.GetPixel(j, i).R
bR = (BigInteger.Pow(y, k) * m) Mod p
If bR Mod 257 = 256 Then
bR = 255
End If
m = gbr_Asli.GetPixel(j, i).G
bG = (BigInteger.Pow(y, k) * m) Mod p
If bG Mod 257 = 256 Then
bG = 255
End If
m = gbr_Asli.GetPixel(j, i).B
bB = (BigInteger.Pow(y, k) * m) Mod p
If bB Mod 257 = 256 Then
bB = 255
End If
gbr_Elgamal.SetPixel(j, i, Color.FromArgb(255, bR, bG, bB))
Next
Next
PictureBox3.Image = gbr_Elgamal
LCitraElgamal.Text = gbr_Elgamal.Width
PCitraElgamal.Text = gbr_Elgamal.Height
sw.Stop()
Dim detik As Double
detik = Math.Round(sw.ElapsedMilliseconds / 1000, 3)
waktuElgamal.Text += sw.ElapsedMilliseconds.ToString() + " ms / " +
detik.ToString() + " s"
MessageBox.Show("Proses Enkripsi telah selesai", "Enkripsi",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btnKunci_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnKunci.Click
If txtZ0.Text "" Then
Dim z0 As Integer = txtZ0.Text
Form1.getKunci(z0)
txtKunci.Text = Form1.strKunci
Else
MessageBox.Show("Masukkan Kunci Playfair")
End If
End Sub
End Class

Universitas Sumatera Utara

68

Form3 :
Public Class Form3
Dim plain1, plain2, x, p As Integer
Dim a As BigInteger
Private Sub MenuUtamaToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MenuUtamaToolStripMenuItem.Click
Me.Dispose()
End Sub
Private Sub EnkripsiToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles EnkripsiToolStripMenuItem.Click
Dim frm2 As New Form2()
frm2.ShowDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog()
Dim path As String
openFileDialog1.Filter = "bmp Files|*.bmp|png Files|*.png"
openFileDialog1.FileName = "*.bmp"
If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
Dim gbr_Playfair As New Bitmap(openFileDialog1.FileName)
If (gbr_Playfair.Width Mod 2 = 1) Then
MessageBox.Show("Lebar Pixel Gambar tidak bisa Ganjil.")
Exit Sub
End If
PictureBox1.Image = gbr_Playfair
LCitraPlayfair.Text = gbr_Playfair.Width
PCitraPlayfair.Text = gbr_Playfair.Height
path = System.IO.Path.GetFullPath(openFileDialog1.FileName)
Dim fileinfo As New System.IO.FileInfo(path)
Dim size As Double = fileinfo.Length / 1024
SizeCitraPlayfair.Text = (Math.Round(size, 1)).ToString()
NamaCitraPlayfair.Text =
System.IO.Path.GetFileName(openFileDialog1.FileName)
dekripsiPlayfair.Enabled = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim openFileDialog1 As New OpenFileDialog()
Dim path As String
openFileDialog1.Filter = "bmp Files|*.bmp|png Files|*.png"
openFileDialog1.FileName = "*.bmp"
If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
Dim gbr_Elgamal As New Bitmap(openFileDialog1.FileName)
PictureBox3.Image = gbr_Elgamal
LCitraElgamal.Text = gbr_Elgamal.Width
PCitraElgamal.Text = gbr_Elgamal.Height
path = System.IO.Path.GetFullPath(openFileDialog1.FileName)
Dim fileinfo As New System.IO.FileInfo(path)
Dim size As Double = fileinfo.Length / 1024
SizeCitraElgamal.Text = (Math.Round(size, 1)).ToString()
NamaCitraElgamal.Text =
System.IO.Path.GetFileName(openFileDialog1.FileName)
DekripsiElgamal.Enabled = True

Universitas Sumatera Utara

69

End If
End Sub
Private Sub dekripPlayfair(ByVal bigram As Integer(), ByVal Kunci As
Integer(,))
Dim limit As Boolean = False
Dim bigramx As Integer() = New Integer(2) {}
Dim bigramy As Integer() = New Integer(2) {}
For x = 0 To 1
For i = 0 To 15
For j = 0 To 15
If (bigram(x) = Kunci(i, j)) Then
bigramx(x) = i
bigramy(x) = j
limit = True
If (limit = True And x = 2) Then
Exit For
End If
End If
Next
If (limit = True And x = 2) Then
Exit For
End If
Next
Next
If (bigramx(0) = bigramx(1)) Then
If (bigramy(0) = 0) Then
plain1 = Kunci(bigramx(0), 15)
plain2 = Kunci(bigramx(1), bigramy(1))
ElseIf (bigramy(1) = 0) Then
plain1 = Kunci(bigramx(0), bigramy(0) - 1)
plain2 = Kunci(bigramx(1), 15)
Else
plain1 = Kunci(bigramx(0), bigramy(0) - 1)
plain2 = Kunci(bigramx(1), bigramy(1) - 1)
End If
ElseIf (bigramy(0) = bigramy(1)) Then
If (bigramx(0) = 0) Then
plain1 = Kunci(15, bigramy(0))
plain2 = Kunci(bigramx(1) - 1, bigramy(1))
ElseIf (bigramx(1) = 0) Then
plain1 = Kunci(bigramx(0) - 1, bigramy(0))
plain2 = Kunci(15, bigramy(1))
Else
plain1 = Kunci(bigramx(0) - 1, bigramy(0))
plain2 = Kunci(bigramx(1) - 1, bigramy(1))
End If
Else
plain1 = Kunci(bigramx(0), bigramy(1))
plain2 = Kunci(bigramx(1), bigramy(0))
End If
End Sub
Private Sub dekripsiPlayfair_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles dekripsiPlayfair.Click
If txtKunci.Text = "" Then
MessageBox.Show("Generate Kunci Playfair terlebih dulu")
txtZ0.Focus()
Exit Sub
End If

Universitas Sumatera Utara

70

Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim

sw As New Stopwatch
gbr_Asli As Bitmap = New Bitmap(PictureBox1.Image)
gbr_Playfair As Bitmap = New Bitmap(PictureBox1.Image)
x As Integer = gbr_Playfair.Width
y As Integer = gbr_Playfair.Height
bigram As Integer() = New Integer(2) {}
r1, g1, b1, r2, g2, b2 As Integer
rCipher1, gCipher1, bCipher1, rCipher2, gCipher2, bCipher2 As

Integer
waktuPlayfair.Text = "Lama Proses Dekripsi : "
sw.Start()
For i = 0 To y - 1
For j = 0 To x - 1 Step 2
r1 = gbr_Playfair.GetPixel(j, i).R
r2 = gbr_Playfair.GetPixel(j + 1, i).R
bigram(0) = r1
bigram(1) = r2
dekripPlayfair(bigram, Form1.Kunci)
rCipher1 = plain1
rCipher2 = plain2
g1 = gbr_Asli.GetPixel(j, i).G
g2 = gbr_Asli.GetPixel(j + 1, i).G
bigram(0) = g1
bigram(1) = g2
dekripPlayfair(bigram, Form1.Kunci)
gCipher1 = plain1
gCipher2 = plain2
b1 = gbr_Asli.GetPixel(j, i).B
b2 = gbr_Asli.GetPixel(j + 1, i).B
bigram(0) = b1
bigram(1) = b2
dekripPlayfair(bigram, Form1.Kunci)
bCipher1 = plain1
bCipher2 = plain2
gbr_Asli.SetPixel(j, i, Color.FromArgb(255, rCipher1, gCipher1,
bCipher1))
gbr_Asli.SetPixel(j + 1, i, Color.FromArgb(255, rCipher2,
gCipher2, bCipher2))
Next
Next
PictureBox2.Image = gbr_Asli
Dim mse As Double = hitungMSE(PictureBox1.Image, PictureBox2.Image)
LDekrip_Playfair.Text = gbr_Asli.Width
PDekrip_Playfair.Text = gbr_Asli.Height
MSEplayfair.Text = Math.Round(mse, 4)
sw.Stop()
Dim detik As Double
detik = Math.Round(sw.ElapsedMilliseconds / 1000, 3)
waktuPlayfair.Text += sw.ElapsedMilliseconds.ToString() + " ms / " +
detik.ToString() + " s"
MessageBox.Show("Proses Dekripsi telah selesai", "Dekripsi",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub SimpanPlayfair_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SimpanPlayfair.Click

Universitas Sumatera Utara

71

Dim simpan As New SaveFileDialog()
Dim path As String
simpan.Filter = "bmp Files|*.bmp"
simpan.FileName = "*.bmp"
If (simpan.ShowDialog() = DialogResult.OK) Then
PictureBox2.Image.Save(simpan.FileName,
System.Drawing.Imaging.ImageFormat.Bmp)
gbrDekrip_Playfair.Text =
System.IO.Path.GetFileName(simpan.FileName)
path = System.IO.Path.GetFullPath(simpan.FileName)
Dim fileinfo As New System.IO.FileInfo(path)
Dim size As Double = fileinfo.Length / 1024
SizeDekrip_Playfair.Text = (Math.Round(size, 1)).ToString()
MessageBox.Show("Gambar telah berhasil disimpan", "Simpan",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub SimpanElgamal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SimpanElgamal.Click
Dim simpan As New SaveFileDialog()
Dim path As String
simpan.Filter = "bmp Files|*.bmp"
simpan.FileName = "*.bmp"
If (simpan.ShowDialog() = DialogResult.OK) Then
PictureBox4.Image.Save(simpan.FileName,
System.Drawing.Imaging.ImageFormat.Bmp)
gbrDekrip_Elgamal.Text =
System.IO.Path.GetFileName(simpan.FileName)
path = System.IO.Path.GetFullPath(simpan.FileName)
Dim fileinfo As New System.IO.FileInfo(path)
Dim size As Double = fileinfo.Length / 1024
SizeDekrip_Elgamal.Text = (Math.Round(size, 1)).ToString()
MessageBox.Show("Gambar telah berhasil disimpan", "Simpan",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub DekripsiElgamal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles DekripsiElgamal.Click
Dim m As Integer
Dim ax As BigInteger
Dim sw As New Stopwatch
Dim gbr_Asli As Bitmap = New Bitmap(PictureBox3.Image)
Dim gbr_Elgamal As Bitmap = New Bitmap(PictureBox3.Image)
Dim w As Integer = gbr_Elgamal.Width
Dim h As Integer = gbr_Elgamal.Height
Dim bR, bG, bB As Integer
p = keyp.Text
a = keya.Text
x = keyx.Text
waktuElgamal.Text = "Lama Proses Dekripsi : "
sw.Start()
ax = BigInteger.ModPow(a, p - 1 - x, p)
For i = 0 To h - 1
For j = 0 To w - 1
m = gbr_Elgamal.GetPixel(j, i).R
bR = m * ax Mod p
If bR Mod 257 = 256 Then
bR = 255
End If

Universitas Sumatera Utara

72

m = gbr_Elgamal.GetPixel(j, i).G
bG = m * ax Mod p
If bG Mod 257 = 256 Then
bG = 255
End If
m = gbr_Elgamal.GetPixel(j, i).B
bB = m * ax Mod p
If bB Mod 257 = 256 Then
bB = 255
End If
gbr_Asli.SetPixel(j, i, Color.FromArgb(255, bR, bG, bB))
Next
Next
PictureBox4.Image = gbr_Asli
Dim mse As Double = hitungMSE(PictureBox3.Image, PictureBox4.Image)
MSEelgamal.Text = Math.Round(mse, 4)
LDekrip_Elgamal.Text = gbr_Asli.Width
PDekrip_Elgamal.Text = gbr_Asli.Height
sw.Stop()
Dim detik As Double
detik = Math.Round(sw.ElapsedMilliseconds / 1000, 3)
waktuElgamal.Text += sw.ElapsedMilliseconds.ToString() + " ms / " +
detik.ToString() + " s"
MessageBox.Show("Proses Dekripsi telah selesai", "Dekripsi",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Function hitungMSE(ByVal imageAsli As Bitmap, ByVal imageHasil As Bitmap)
As Double
Dim sum As UInt64 = 0
Dim r1, r2, g1, g2, b1, b2 As Double
Dim MSE As Double
For i = 0 To imageAsli.Height - 1
For j = 0 To imageAsli.Width - 1
r1 = imageAsli.GetPixel(j, i).R
r2 = imageHasil.GetPixel(j, i).R
sum += Math.Pow(r1 - r2, 2)
g1 = imageAsli.GetPixel(j, i).G
g2 = imageHasil.GetPixel(j, i).G
sum += Math.Pow(g1 - g2, 2)
b1 = imageAsli.GetPixel(j, i).B
b2 = imageHasil.GetPixel(j, i).B
sum += Math.Pow(b1 - b2, 2)
Next
Next
MSE = sum / (imageAsli.Height * imageAsli.Width)
Return MSE
End Function
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
keyp.Text =
Application.OpenForms("Form2").Controls("GroupBox2").Controls("GroupBox4").Cont
rols("keyp").Text
keya.Text =
Application.OpenForms("Form2").Controls("GroupBox2").Controls("GroupBox4").Cont
rols("keya").Text

Universitas Sumatera Utara

73

keyx.Text =
Application.OpenForms("Form2").Controls("GroupBox2").Controls("GroupBox4").Cont
rols("keyx").Text
Catch ex As Exception
End Try

End Sub
Private Sub btnKunci_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnKunci.Click
If txtZ0.Text "" Then
Dim z0 As Integer = txtZ0.Text
Form1.getKunci(z0)
txtKunci.Text = Form1.strKunci
Else
MessageBox.Show("Masukkan Kunci Playfair")
End If
End Sub
End Class

Universitas Sumatera Utara

CURRICULUM VITAE

Nama

: Ahmad Syawqi Lubis

Tempat/Tanggal Lahir : Medan , 3 Juni 1989
Alamat orang tua

: Jl. Seroja 6 No. 28 P.Helvetia Medan

Alamat Sekarang

: Jl. Seroja 6 No. 28 P.Helvetia Medan

No.HP

: 082367524890

Email

: cukongqie@live.com

Riwayat Pendidikan :

TK Tunas Mekkar YON-ZIPUR Helvetia Medan dari Tahun 1994 s/d Tahun 1995
SD 064981 dari Tahun 1995 s/d Tahun 2001.
Madrasah Tsanawiyah Negeri 2 Medan Tahun 2001 s/d Tahun 2004.
Madrasah Aliyah Negeri 2 Model Medan dari Tahun 2003 /d Tahun 2007.
Universitas Sumatera Utara dari Tahun 2007 s/d 2014

Ketrampilan yang dikuasai :
1. IT Support .

Universitas Sumatera Utara