Muhammad Suhairi Arafat

Sabtu, 29 Juni 2013

Tugas Latihan Kriptografi








Listing Program

PublicClass Form1

PrivateSub CaesarChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChiperToolStripMenuItem.Click
        Caesar_Chiper.MdiParent = Me
        Caesar_Chiper.Show()
EndSub

PrivateSub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
End
EndSub


PrivateSub VernamChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VernamChiperToolStripMenuItem.Click
        Vernam_Chiper.MdiParent = Me
        Vernam_Chiper.Show()
EndSub

PrivateSub VigenereChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VigenereChiperToolStripMenuItem.Click
        Vigenere_Chiper.MdiParent = Me
        Vigenere_Chiper.Show()
EndSub

PrivateSub DesChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DesChiperToolStripMenuItem.Click
        Des_Chiper.MdiParent = Me
        Des_Chiper.Show()
EndSub
EndClass

A. Program Caesar_Chiper

 1.click Menu filepilih Caesar Chiper



Maka akantampil Program Caesar Chiper
 


LISTING PROGRAM :
PublicClass Caesar_Chiper

PrivateSub Caesar_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        Plainteks.Text = ""
        Chiperteks.Text = ""
EndSub

PrivateSub BtnEnkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkripsi.Click
Dim jumlah AsDouble = Len(Plainteks.Text)
Dim x AsString
Dim xkalimat AsString = ""
Dim bil AsInteger
For i = 1 To jumlah
            x = Mid(Plainteks.Text, i, 1)
            bil = Asc(x) + 3
            x = Chr(bil)
            xkalimat = xkalimat + x
Next i
        Chiperteks.Text = xkalimat
EndSub

PrivateSub Btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnhapus.Click
        Chiperteks.Text = ""
        Plainteks.Text = ""
EndSub

PrivateSub Btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnkeluar.Click
End
EndSub

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
        Form1.Show()
EndSub
EndClass

B. Program Gronsfeld Chiper
1. Click Menu File dan Pilih Gronsfeld Chiper

2. Maka akan tampil Program Gronsfeld Chiper


LISTING PROGRAM GRONSFELD_CHIPER

PublicClass Gronsfeld

PrivateSub btnkembali_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles btnkembali.Click
Me.Hide()
        Formkriptografi.Show()

EndSub

PrivateSub Btnkeluar_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles Btnkeluar.Click
End

EndSub

PrivateSub Gronsfeld_Load(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesMyBase.Load
        Plainteks.Text = ""
        Chiperteks.Text = ""

EndSub

PrivateSub Btnenkripsi_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles Btnenkripsi.Click
Dim J AsInteger
Dim Jum AsInteger
DimsKey AsString
DimnKata AsInteger
DimnKunci AsString
DimsKata AsString
DimsPlain AsString= ""
DimnEnc AsInteger
        J = 0
        sKata = Plainteks.Text
        Jum = Len(sKata)
        sKey = Kunci.Text
For i = 1 To Jum
IfJ = Len(sKey) Then
                J = 1
Else
                J = J + 1
EndIf
            nKata = Asc(Mid(sKata, i, 1)) - 65
            nKunci = Asc(Mid(sKey, J, 1)) - 65
            nEnc = ((nKata + nKunci) Mod 26)
            sPlain = sPlain & Chr((nEnc))
Next i
        Chiperteks.Text = sPlain
EndSub

PrivateSub Btnhapus_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles Btnhapus.Click
        Plainteks.Text = ""
        Chiperteks.Text = ""
        Kunci.Text = ""
EndSub

PrivateSub Plainteks_KeyPress(ByValsender AsObject, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) HandlesPlainteks.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dimtombol AsInteger= Asc(e.KeyChar)
IfNot (((tombol >= 65) And(tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf
EndSub

PrivateSub Plainteks_TextChanged(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles Plainteks.TextChanged

EndSub

PrivateSub Kunci_KeyPress(ByValsender AsObject, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) HandlesKunci.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dimtombol AsInteger= Asc(e.KeyChar)
IfNot (((tombol >= 65) And(tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf
EndSub

PrivateSub Kunci_TextChanged(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles Kunci.TextChanged

EndSub
EndClass


C. Program Vernam Chiper
1. Click Menu File dan Pilih Vernam Chiper





2. Maka akan Muncul Program Vernam Chiper


LISTING PROGRAM
PublicClass Vernam_Chiper


PrivateSub Vernam_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        Plainteks.Text = ""
        Chiperteks.Text = ""
        kunci.Text = ""
EndSub

PrivateSub BtnEnkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkripsi.Click
Dim J AsInteger
Dim Jum AsInteger
Dim sKey AsString
Dim nKata AsInteger
Dim nKunci AsInteger
Dim sKata AsString
Dim sPlain AsString = ""
Dim nEnc AsInteger
        J = 0
        sKata = Plainteks.Text
        Jum = Len(sKata)
        sKey = Kunci.Text
For i = 1 To Jum
If J = Len(sKey) Then
                J = 1
Else
                J = J + 1
EndIf
            nKata = Asc(Mid(sKata, i, 1)) - 65
            nKunci = Asc(Mid(sKey, J, 1)) - 65
            nEnc = ((nKata + nKunci) Mod 26)
            sPlain = sPlain & Chr((nEnc) + 65)
Next i
        Chiperteks.Text = sPlain




EndSub

PrivateSub Plainteks_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Plainteks.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dim tombol AsInteger = Asc(e.KeyChar)
IfNot (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf

EndSub

PrivateSub Kunci_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Kunci.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dim tombol AsInteger = Asc(e.KeyChar)
IfNot (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf

EndSub

PrivateSub Btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnhapus.Click
        Plainteks.Text = ""
        Kunci.Text = ""
        Chiperteks.Text = ""

EndSub

PrivateSub Btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnkeluar.Click
End
EndSub


PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
        Form1.Show()

EndSub
EndClass


D. Program Vigenere Chiper
 1. Click Menu File Pada Vigenere Chiper




D. Program Vigenere Chiper

 1. Maka Akan Muncul Tampilan Seprti ini :


LISTING PROGRAM
PublicClass Vigenere_Chiper


PrivateSub Vigenere_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        Plainteks.Text = ""
        Chiperteks.Text = ""

EndSub

PrivateSub BtnEnkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkripsi.Click
Dim J AsInteger
Dim Jum AsInteger
Dim sKey AsString
Dim nKata AsInteger
Dim nKunci AsInteger
Dim sKata AsString
Dim sPlain AsString = ""
Dim nEnc AsInteger
        J = 0
        sKata = Plainteks.Text
        Jum = Len(sKata)
        sKey = Kunci.Text
For i = 1 To Jum
If J = Len(sKey) Then
                J = 1
Else
                J = J + 1
EndIf
            nKata = Asc(Mid(sKata, i, 1)) + 0
            nKunci = Asc(Mid(sKey, J, 1)) + 0
            nEnc = ((nKata + nKunci) Mod 256)
            sPlain = sPlain & Chr((nEnc))
Next i
        Chiperteks.Text = sPlain

EndSub

PrivateSub Plainteks_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Plainteks.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dim tombol AsInteger = Asc(e.KeyChar)
IfNot (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf

EndSub

PrivateSub Kunci_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Kunci.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dim tombol AsInteger = Asc(e.KeyChar)
IfNot (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf

EndSub

PrivateSub Btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnhapus.Click
        Plainteks.Text = ""
        Chiperteks.Text = ""
        Kunci.Text = ""
EndSub

PrivateSub Btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnkeluar.Click
End
EndSub

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
        Form1.Show()
EndSub
EndClass



E. Program Des Chiper

1. Click Menu File danP ilih Des Chiper 


2. Maka Akan Muncul Program Des Chiper






LISTING PROGRAM
PublicClass Des_Chiper


PrivateSub BtnEnkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkripsi.Click
Dim kunci AsString, kunciChar AsString, kata baru AsString
Dim Pos AsInteger
Dim i AsInteger, Side1 AsString, Side2 AsString
Dim nEnc AsInteger
        Pos = 1
For i = 1 To Len(Plainteks.Text)
            Plainteks.Text = Mid(Plainteks.Text, i, 1)
            Kunci.Text = Mid(Kunci.Text, Pos, 1)
            Chiperteks.Text = Chiperteks.Text & Chr(Asc(OfChar)() Xor Asc(Kunci.Text))
If Pos = Len(Kunci) Then Pos = 0
            Pos = Pos + 1
Next i
If Len(Chiperteks.Text) Mod 2 = 0 Then
            Side1 = StrReverse(Left(Chiperteks.Text, (Len(Chiperteks.Text) / 2)))
            Side2 = StrReverse(Right(Chiperteks.Text, (Len(Chiperteks.Text) / 2)))
            Chiperteks.Text = Side1 & Side2
EndIf
        nEnc = Chiperteks.Text


EndSub
PrivateSub Plainteks_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Plainteks.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dim tombol AsInteger = Asc(e.KeyChar)
IfNot (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf

EndSub

PrivateSub Kunci_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Kunci.KeyPress
        e.KeyChar = UCase(e.KeyChar)
Dim tombol AsInteger = Asc(e.KeyChar)
IfNot (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
            e.Handled = True
EndIf

EndSub

PrivateSub Btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnhapus.Click
        Plainteks.Text = ""
        Chiperteks.Text = ""
        Kunci.Text = ""
EndSub

PrivateSub Btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnkeluar.Click
End
EndSub

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
        Form1.Show()
EndSub
EndClass
EndSub

PrivateSub Des_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        Plainteks.Text = ""
        Chiperteks.Text = ""

EndSub
EndClass







 
n
o
i
t
a
r
e
n
e
G
e
L
p
M
i
S
t
a
f
a
r
A