Sie sind auf Seite 1von 10

LISTING PROGRAM

1. Login Option Explicit Private Sub txtUser_Click() txtPwd.Locked = False txtPwd.SetFocus End Sub Private Sub cmdCancel_Click() End End Sub Private Sub cmdOK_Click() On Error Resume Next If UCase(txtUser.Text) <> "ROSI" And txtPwd.Text <> "123" Then MsgBox "Password salah" txtPwd = "" txtUser = "" txtUser.SetFocus Else Me.Hide frmMenu.Show End If End Sub Private Sub Form_Activate() txtPwd = "" txtUser = "" txtUser.SetFocus End Sub Private Sub txtPwd_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdOk.Enabled = True cmdOk.SetFocus End If End Sub Private Sub txtUser_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then txtPwd.Locked = False txtPwd.SetFocus End If End Sub

2. MenuUtama Private Sub Abt_Click() frmAbout.Show End Sub Private Sub exi_Click()

Universitas Sumatera Utara

End End Sub Private Sub Hlp_Click() frmHelp.Show End Sub Private Sub Md5_Click() FSHATest.Show End Sub Private Sub Veri_Click() frmVerifikasi.Show End Sub 3. MD-5 Option Explicit Dim rsCari As Recordset Dim rsSave As Recordset Dim Id As Integer Dim CN As Connection Dim Tambah As Boolean Dim Cari As Boolean Dim X As String Private Sub cmdBersih_Click() Call Bersih End Sub Sub Bersih() Text1.Enabled = False Text2.Enabled = False Text1.Text = "" Text2.Text = "" Id = 0 cmdHapus.Enabled = False cmdNew.Enabled = True cmdCari.Enabled = True cmdHash.Enabled = False cmdNew.SetFocus End Sub Private Sub cmdCari_Click() Tambah = False Cari = True Text1.Enabled = True Text1.Text = "" Text1.SetFocus End Sub Private Sub cmdCopy1_Click() Clipboard.Clear Clipboard.SetText Text1 End Sub Private Sub cmdCopy2_Click() Clipboard.Clear Clipboard.SetText Text2

Universitas Sumatera Utara

End Sub

Private Sub cmdExit_Click() Unload Me End Sub Private Sub cmdHapus_Click() cmdHapus.Enabled = False X = MsgBox("Data mau dihapus ?", vbYesNo) If X = vbYes Then rsCari.Delete Set rsCari = Nothing MsgBox "Message digest sudah dihapus" Else Set rsCari = Nothing End If Call Bersih Call Segar End Sub Private Sub cmdHash_Click() cmdHash.Enabled = False Dim oSHA As clsSHA Set oSHA = New clsSHA Text2.Text = oSHA.SHA1(Text1.Text) Set oSHA = Nothing cmdSave.Enabled = True cmdSave.SetFocus End Sub Private Sub cmdNew_Click() Tambah = True Cari = False cmdNew.Enabled = False Set rsCari = New ADODB.Recordset rsCari.Open "select * from tPesan order by IdPesan desc", _ CN, 1, 2 If Not rsCari.EOF Then Id = rsCari!IdPesan + 1 Else Id = 1 End If Set rsCari = Nothing Text1.Enabled = True Text2.Enabled = True Text1.Text = "" Text2.Text = "" Text1.SetFocus End Sub Private Sub cmdSave_Click() cmdSave.Enabled = False Set rsSave = New ADODB.Recordset rsSave.Open "tPesan", CN, 1, 2 rsSave.AddNew

Universitas Sumatera Utara

rsSave!IdPesan = Id rsSave!Pesan = Text1.Text rsSave!md = Text2.Text rsSave.Update Text1.Text = "" Text2.Text = "" Id = 0 Text1.Enabled = False Text2.Enabled = False MsgBox "Data pesan tersimpan .." Call Segar Set rsSave = Nothing cmdNew.Enabled = True cmdNew.SetFocus End Sub Sub Segar() Set rsCari = New ADODB.Recordset rsCari.Open "select * from tPesan order by IdPesan asc", CN, 1, 2 Set rsCari = Nothing Adodc1.Refresh grid.TextMatrix(0, grid.TextMatrix(0, grid.TextMatrix(0, grid.TextMatrix(0,

0) 1) 2) 3)

= = = =

"" "Id" "Pesan" "MD"

grid.ColWidth(0) = 0 grid.ColWidth(1) = 1000 grid.ColWidth(2) = 2500 grid.ColWidth(3) = 5500 grid.Refresh End Sub Private Sub Form_Activate() Call Segar Text1.Enabled = False Text2.Enabled = False cmdSave.Enabled = False cmdHash.Enabled = False cmdNew.Enabled = True cmdNew.SetFocus End Sub Private Sub Form_Load() Set CN = New ADODB.Connection CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51; _ Persist Security Info=False;Data Source=" & _ App.Path & "\dbMD5.mdb" CN.Open End Sub Private Sub Text1_Change() If Len(Text1.Text) < 1 Then cmdHash.Enabled = False Exit Sub Else

Universitas Sumatera Utara

If Tambah = True Then cmdHash.Enabled = True ElseIf Cari = True Then End If End If End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then On Error Resume Next If Cari = True Then Set rsCari = New ADODB.Recordset rsCari.Open "select * from tPesan where Pesan='" & _ Text1.Text & "'", CN, 1, 2 If Not rsCari.EOF Then Text2.Text = rsCari!md Else MsgBox "Pesan tidak ditemukan" Text1.SetFocus End If Set rsCari = Nothing End If End If End Sub

4. Verifikasi Option Explicit Dim rsCari As Recordset Dim rsSave As Recordset Dim Id As Integer Dim CN As Connection Dim Tambah As Boolean Dim Cari As Boolean Dim MD1, MD2 As String * 200 Dim bolAda As Boolean Private Sub cmdBersih_Click() Call Bersih End Sub Private Sub cmdExit_Click() Unload Me End Sub Private Sub cmdNew_Click() cmdNew.Enabled = False Tambah = True

Universitas Sumatera Utara

Cari = False txtPesan.Enabled = True txtPesan.SetFocus End Sub Sub Veri() Set rsCari = New ADODB.Recordset rsCari.Open "select * from tPesan where Pesan='" _ & txtPesan.Text & "'", CN, 1, 2 If Not rsCari.EOF Then MD2 = rsCari!md bolAda = True Else bolAda = False MsgBox "Message digets verifikasi tidak tersedia" MD2 = "" End If Set rsCari = Nothing txtMD2.Text = MD2 End Sub Private Sub cmdVeri_Click() Call Veri cmdVeri.Enabled = False Dim oSHA As clsSHA Set oSHA = New clsSHA MD1 = oSHA.SHA1(txtPesan.Text) txtMD1.Text = MD1 Set oSHA = Nothing If bolAda = True Then If RTrim(MD1) = RTrim(MD2) Then lblVeri.Caption = "Pesan masih asli, belum berubah" Else lblVeri.Caption = "Pesan sudah berubah" End If End If End Sub Private Sub Form_Activate() Call Bersih End Sub Private Sub Form_Load() Set CN = New ADODB.Connection CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51; _ Persist Security Info=False;Data Source=" _ & App.Path & "\dbMD5.mdb" CN.Open End Sub Sub Bersih() txtPesan = "" txtMD1 = "" txtMD2 = ""

Universitas Sumatera Utara

lblVeri = "" bolAda = False txtPesan.Enabled = False cmdVeri.Enabled = False txtMD1.Enabled = False txtMD2.Enabled = False cmdNew.Enabled = True cmdNew.SetFocus End Sub Private Sub txtPesan_Change() If Len(txtPesan.Text) < 1 Then cmdVeri.Enabled = False Exit Sub Else If Tambah = True Then cmdVeri.Enabled = True ElseIf Cari = True Then End If End If End Sub

5. Module Option Explicit Private Declare Sub CopyMem Lib "kernel32" _ Alias "RtlMoveMemory" (Destination As Any, Source As Any, _ ByVal Length As Long) Private byteArray() As Byte Private hiByte As Long Private hiBound As Long Private Type Word B0 As Byte B1 As Byte B2 As Byte B3 As Byte End Type Private Sub Reset() hiByte = 0 hiBound = 1024 ReDim byteArray(hiBound) End Sub Private Sub Append(ByRef StringData As String, Optional _ Length As Long) Dim DataLength As Long If Length > 0 Then DataLength = Length Else _ DataLength = Len(StringData) If DataLength + hiByte > hiBound Then hiBound = hiBound + 1024 ReDim Preserve byteArray(hiBound) End If CopyMem ByVal VarPtr(byteArray(hiByte)), ByVal _ StringData, DataLength hiByte = hiByte + DataLength End Sub Private Property Get GData() As String

Universitas Sumatera Utara

Dim StringData As String StringData = Space(hiByte) CopyMem ByVal StringData, ByVal VarPtr(byteArray(0)), hiByte GData = StringData End Property Private Function AndW(w1 As Word, w2 As Word) As Word AndW.B0 = w1.B0 And w2.B0 AndW.B1 = w1.B1 And w2.B1 AndW.B2 = w1.B2 And w2.B2 AndW.B3 = w1.B3 And w2.B3 End Function Private Function OrW(w1 As Word, w2 As Word) As Word OrW.B0 = w1.B0 Or w2.B0 OrW.B1 = w1.B1 Or w2.B1 OrW.B2 = w1.B2 Or w2.B2 OrW.B3 = w1.B3 Or w2.B3 End Function Private Function XorW(w1 As Word, w2 As Word) As Word XorW.B0 = w1.B0 Xor w2.B0 XorW.B1 = w1.B1 Xor w2.B1 XorW.B2 = w1.B2 Xor w2.B2 XorW.B3 = w1.B3 Xor w2.B3 End Function

Private Function NotW(w As Word) As Word NotW.B0 = Not w.B0 NotW.B1 = Not w.B1 NotW.B2 = Not w.B2 NotW.B3 = Not w.B3 End Function Private Function AddW(w1 As Word, w2 As Word) As Word Dim I As Integer, w As Word I = CInt(w1.B3) + w.B3 = I Mod 256 I = CInt(w1.B2) + w.B2 = I Mod 256 I = CInt(w1.B1) + w.B1 = I Mod 256 I = CInt(w1.B0) + w.B0 = I Mod 256 AddW = w End Function w2.B3 w2.B2 + (I \ 256) w2.B1 + (I \ 256) w2.B0 + (I \ 256)

Private Function CircShiftLeftW(w As Word, n As Integer) As Word Dim d1 As Double, d2 As Double d1 = WordToDouble(w) d2 = d1 d1 = d1 * (2 ^ n) d2 = d2 / (2 ^ (32 - n)) CircShiftLeftW = OrW(DoubleToWord(d1), DoubleToWord(d2)) End Function Private Function WordToHex(w As Word) As String

Universitas Sumatera Utara

WordToHex = Right$("0" & Hex$(w.B0), 2) & _ Right$("0" & Hex$(w.B1), 2) & Right$("0" & Hex$(w.B2), 2) & _ Right$("0" & Hex$(w.B3),2) End Function Private Function HexToWord(H As String) As Word HexToWord = DoubleToWord(Val("&H" & H & "#")) End Function Private Function DoubleToWord(n As Double) As Word DoubleToWord.B0 = Int(DMod(n, 2 ^ 32) / (2 ^ 24)) DoubleToWord.B1 = Int(DMod(n, 2 ^ 24) / (2 ^ 16)) DoubleToWord.B2 = Int(DMod(n, 2 ^ 16) / (2 ^ 8)) DoubleToWord.B3 = Int(DMod(n, 2 ^ 8)) End Function Private Function WordToDouble(w As Word) As Double WordToDouble = (w.B0 * (2 ^ 24)) + (w.B1 * (2 ^ 16)) + _ (w.B2 * (2 ^ 8)) + w.B3 End Function Private Function DMod(value As Double, divisor As Double) As Double DMod = value - (Int(value / divisor) * divisor) If DMod < 0 Then DMod = DMod + divisor End Function Private Function F(t As Integer, B As Word, C As Word, D As Word) _ As Word Select Case t Case Is <= 19 F = OrW(AndW(B, C), AndW(NotW(B), D)) Case Is <= 39 F = XorW(XorW(B, C), D) Case Is <= 59 F = OrW(OrW(AndW(B, C), AndW(B, D)), AndW(C, D)) Case Else F = XorW(XorW(B, C), D) End Select End Function Public Function SHA1(inMessage As String) As String Dim inLen As Long, inLenW As Word, padMessage As String, _ numBlocks As Long, w(0 To 79) As Word, blockText As _ String, wordText As String, I As Long, t As Integer, _ temp As Word, K(0 To 3) As Word, H0 As Word, H1 As _ Word, H2 As Word, H3 As Word, H4 As Word, A As Word, B _ As Word, C As Word, D As Word, E As Word inLen = Len(inMessage) inLenW = DoubleToWord(CDbl(inLen) * 8) Reset Append Append Append Append Append Append Append

inMessage Chr$(128) String$((128 - (inLen Mod 64) - 9) Mod 64, Chr$(0)) String$(4, Chr$(0)) Chr$(inLenW.B0) Chr$(inLenW.B1) Chr$(inLenW.B2)

Universitas Sumatera Utara

Append Chr$(inLenW.B3) padMessage = GData Reset numBlocks = Len(padMessage) / 64 K(0) = HexToWord("5A827999") K(1) = HexToWord("6ED9EBA1") K(2) = HexToWord("8F1BBCDC") K(3) = HexToWord("CA62C1D6") H0 = HexToWord("67452301") H1 = HexToWord("EFCDAB89") H2 = HexToWord("98BADCFE") H3 = HexToWord("10325476") H4 = HexToWord("C3D2E1F0") For I = 0 To numBlocks - 1 blockText = Mid$(padMessage, (I * 64) + 1, 64) For t = 0 To 15 wordText = Mid$(blockText, (t * 4) + 1, 4) w(t).B0 = Asc(Mid$(wordText, 1, 1)) w(t).B1 = Asc(Mid$(wordText, 2, 1)) w(t).B2 = Asc(Mid$(wordText, 3, 1)) w(t).B3 = Asc(Mid$(wordText, 4, 1)) Next t For t = 16 To 79 w(t) = CircShiftLeftW(XorW(XorW(XorW(w(t - 3), w(t - 8)), _ w(t - 14)), w(t - 16)), 1) Next t A = H0 B = H1 C = H2 D = H3 E = H4

For t = 0 To 79 temp = AddW(AddW(AddW(AddW(CircShiftLeftW(A, 5), F(t, _ B, C, D)), E), w(t)), K(t \ 20)) E = D D = C C = CircShiftLeftW(B, 30) B = A A = temp Next t H0 = AddW(H0, A) H1 = AddW(H1, B) H2 = AddW(H2, C) H3 = AddW(H3, D) H4 = AddW(H4, E) Next I SHA1 = WordToHex(H0) & WordToHex(H1) & WordToHex(H2) & _ WordToHex(H3) _ & WordToHex(H4) End Function

Universitas Sumatera Utara

Das könnte Ihnen auch gefallen