63
DAFTAR PUSTAKA
Dharwanti and Wahono. 2003. Panduan Singkat
Bahasa Pemodelan
Objek
Standar.Yogyakarta:Andi. Dony Ariyus. 2008. Pengantar Ilmu Kriptografi Teori, Analisis, dan Implementasi. Yogyakarta:Andi. Fowler, Martin. 2003. Panduan Singkat Bahasa Pemodelan Objek Standar. Yogyakarta:Andi. Henk C. A. van Tilborg. 2005. Encyclopedia of cryptography and security Munawar. 2005. Pemodelan Visual dengan UML. Yogyakarta: Graha Ilmu. Munir, Rinaldi, Kritografi, Penerbit Informatika, 2006. Pressman, Roger S. 1997. Rekayasa Perangkat Lunak Pendekatan praktisi. Yogyakarta:Andi.
L1
LAMPIRAN PROGRAM
Option Explicit Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'Fungsi Shift Right sebanyak pnRotate bit Public Function FShiftRight(pcText As String, pnRotate As Long) As String FShiftRight = String(pnRotate, "0") & Left(pcText, Len(pcText) pnRotate) End Function 'BINER KE HEKSA Public Function FBinerToHex(pcText As String) As String Dim i As Integer For i = 1 To Len(pcText) Step 4 FBinerToHex = FBinerToHex & Hex(FBinerToDec(Mid(pcText, i, 4))) Next i End Function 'HEKSA KE BINER Public Function FHexToBiner(pcText As String) As String Dim i As Integer For i = 1 To Len(pcText) FHexToBiner = FHexToBiner & FormatS(FDecToBiner(FHexToDec1 (UCase(Mid(pcText, i, 1)))), "0", 4) Next i End Function Public Function FAddBiner(pcBiner1 As String, pcBiner2 As String, Optional pnLength As Integer = -1) As String Dim i As Long Dim pcB1 As String Dim pcB2 As String
Dim Counter As Integer Dim Hasil As Integer ‘Apabila Panjang Biner Tidak Sama pcB1 = pcBiner1 pcB2 = pcBiner2 i = IIf(Len(pcB1) > Len(pcB2), Len(pcB1), Len(pcB2)) pcB1 = FormatS(pcB1, "0", i) pcB2 = FormatS(pcB2, "0", i) 'loop Counter = 0 For i = Len(pcB1) To 1 Step -1 Hasil = Val(Mid(pcB1, i, 1)) + Val(Mid(pcB2, i, 1)) Hasil = Hasil + Counter Counter = Hasil \ 2 FAddBiner = FAddBiner & Format(Hasil Mod 2) Next i If Counter = 1 Then FAddBiner = FAddBiner & "1" 'panjang text i = pnLength If i = -1 Then i = Len(pcB1) End If 'Hasil Penjumlahan Biner FAddBiner = Right(FReverse(FAddBiner), i) If Len(FAddBiner) < i Then FAddBiner = FormatS(FAddBiner, "0", i) End If End Function 'DESIMAL KE BINER Public Function FDecToBiner(ByVal pnAngka As Double) As String Dim nLoop As Double Dim nHasilBagi As Double Dim nSisaBagi As Double Dim cBiner1 As String
L2
Dim cBiner2 As String nHasilBagi = pnAngka While nHasilBagi <> 0 nSisaBagi = FMod(nHasilBagi, 2) cBiner1 = cBiner1 & Format(nSisaBagi) nHasilBagi = FDiv(nHasilBagi, 2) Wend If cBiner1 = "" Then cBiner1 = "0" 'Ambil Terbalik For nLoop = Len(cBiner1) To 1 Step -1 cBiner2 = cBiner2 & Mid(cBiner1, nLoop, 1) Next nLoop 'Angka Biner FDecToBiner = cBiner End Function 'BINER KE DESIMAL Public Function FBinerToDec(pcText As String) As Double Dim nLoop As Double Dim nHasil As Double nHasil = 0 'Konversi Dari Belakang For nLoop = Len(pcText) To 1 Step -1 If Mid(pcText, nLoop, 1) = "1" Then nHasil = nHasil + (2 ^ (Len(pcText) - nLoop)) End If Next nLoop 'Angka Desimal FBinerToDec = nHasil End Function 'DESIMAL KE HEKSA Public Function FDecToHex(pnAngka As Double) As String Dim nLoop As Double Dim nHasilBagi As Double Dim nSisaBagi As Double Dim cHex1 As String Dim cHex2 As String nHasilBagi = pnAngka While nHasilBagi <> 0 nSisaBagi = FMod(nHasilBagi, 16)
cHex1 = cHex1 & FDecToHex1(nSisaBagi) nHasilBagi = FDiv(nHasilBagi, 16) Wend If cHex1 = "" Then cHex1 = "0" 'Ambil Terbalik For nLoop = Len(cHex1) To 1 Step -1 cHex2 = cHex2 & Mid(cHex1, nLoop, 1) Next nLoop 'Angka Heksa FDecToHex = cHex2 End Function 'Konversi 1 Karakter Dari Desimal Ke Heksa Public Function FDecToHex1(pnAngka As Double) As String Select Case pnAngka Case 0 To 9: FDecToHex1 = Format(pnAngka) Case 10: FDecToHex1 = "A" Case 11: FDecToHex1 = "B" Case 12: FDecToHex1 = "C" Case 13: FDecToHex1 = "D" Case 14: FDecToHex1 = "E" Case 15: FDecToHex1 = "F" End Select End Function 'HEKSA DE DESIMAL Public Function FHexToDec(pcText As String) As Double Dim nLoop As Double Dim nHasil As Double nHasil = 0 'Konversi dari belakang For nLoop = Len(pcText) To 1 Step -1 nHasil = nHasil + FHexToDec1(Mid(pcText, nLoop, 1)) * (16 ^ (Len(pcText) nLoop)) Next nLoop 'Angka Desimal FHexToDec = nHasil End Function
L3
'Konversi 1 Karakter Dari Heksa Ke Desimal Public Function FHexToDec1(pcText As String) As Double Select Case pcText Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" FHexToDec1 = pcText Case "A": FHexToDec1 = 10 Case "B": FHexToDec1 = 11 Case "C": FHexToDec1 = 12 Case "D": FHexToDec1 = 13 Case "E": FHexToDec1 = 14 Case "F": FHexToDec1 = 15 End Select End Function 'Ambil Bentuk Proses Public Function Bentuk(pcBinerText As String, Optional pnLenBiner As Long = -1) As String If pnLenBiner = -1 Then pnLenBiner = Len(pcBinerText) End If If strB = "B" Then Bentuk = pcBinerText Else Bentuk = FBinerToHex(FormatS(pcBinerTex t, "0", pnLenBiner)) End If End Function 'Fungsi Mod Public Function Double, pnA2 As Double Dim nMod As nMod = pnA1 FMod = pnA1 Int(nMod)) End Function 'Fungsi Div Public Function Double, pnA2 As Double Dim nDiv As
FMod(pnA1 As Double) As Double / pnA2 - (pnA2 *
FDiv(pnA1 As Double) As Double
nDiv = pnA1 / pnA2 FDiv = Int(nDiv) End Function 'Fungsi XOR Public Function FOpBiner(pcTipe As String, pcText1 As String, pcText2 As String, Optional pnByte As Long = 0) As String Dim nF As Long Dim cXOR As String Dim nByte1 As Long Dim cText1 As String Dim cText2 As String Dim cHasilXOR As String 'Banyak byte nByte1 = pnByte If nByte1 = 0 Then 'Ambil yang terpanjang If Len(pcText1) > Len(pcText2) Then nByte1 = Len(pcText1) Else nByte1 = Len(pcText2) End If End If cText1 = FormatS(pcText1, "0", nByte1) 'Text-1 cText2 = FormatS(pcText2, "0", nByte1) 'Text-2 For nF = 1 To nByte1 If pcTipe = "XOR" Then cXOR = cXOR & IIf(Mid(cText1, nF, 1) = Mid(cText2, nF, 1), "0", "1") ElseIf pcTipe = "AND" Then cXOR = cXOR & IIf(Mid(cText1, nF, 1) = "0" Or Mid(cText2, nF, 1) = "0", "0", "1") ElseIf pcTipe = "OR" Then cXOR = cXOR & IIf(Mid(cText1, nF, 1) = "1" Or Mid(cText2, nF, 1) = "1", "1", "0") End If Next nF 'Hasil XOR cHasilXOR = FormatS(cXOR, "0", nByte1) FOpBiner = cHasilXOR End Function
L4
'Untuk Memformat String Pctext Sepanjang Pnlength, Kosong Diganti Dengan Pczerotext Public Function FormatS(ByVal pcText As String, pcZeroText As String, pnLength As Long) As String If Len(pcText) > pnLength Then 'Jika lebih besar, maka cut pcText = Left(pcText, pnLength) ElseIf Len(pcText) < pnLength Then 'Jika lebih kecil, maka tambah FormatS = String(pnLength - Len(pcText), pcZeroText) & pcText Else FormatS = pcText End If End Function 'Delay - sleep Public Sub Delay(pnDelay As Integer) If pnDelay > 0 Then DoEvents Sleep pnDelay End If End Sub 'Balikkan Isi Text Public Function FReverse(pcText As String) As String Dim strReverse As String Dim i As Long For i = Len(pcText) To 1 Step -1 strReverse = strReverse & Mid(pcText, i, 1) Next i 'Hasil FReverse = strReverse End Function Option Explicit 'Variabel S-BOX Public TT(7) As String Public T(256) As String 'Kunci Public 'Kunci Public Public
WAKE - dalam biner strKunciBiner As String WAKE - dalam biner strPlain As String strCipher As String
Public strKunci As String Public nPutaran As Integer 'Bentuk Output - Biner / Heksa Public strB As String 'PROSES S-BOX Public Sub ProsesSBox(pcKunci As String) Dim X As String Dim Z As String Dim N As Integer Dim Temp As String '1. Inisialisasi nilai TT[0] - T[7] TT(0) = FHexToBiner("726a8f3b") TT(1) = FHexToBiner("e69a3b5c") TT(2) = FHexToBiner("d3c71fe5") TT(3) = FHexToBiner("ab3c73d2") TT(4) = FHexToBiner("4d3a8eb3") TT(5) = FHexToBiner("0396d6e8") TT(6) = FHexToBiner("3d4c2f7a") TT(7) = FHexToBiner("9ee27cf3") '2. Inisialisasi nilai awal untuk T[0] - T[3] ' Pecah kunci (128 bit) menjadi 4 kelompok X = "" For N = 1 To Len(pcKunci) X = X & FormatS(FDecToBiner(Asc(Mid(pc Kunci, N, 1))), "0", 8) Next N T(0) = Mid(X, 1, 32) T(1) = Mid(X, 33, 32) T(2) = Mid(X, 65, 32) T(3) = Mid(X, 97, 32) '3. Untuk N = 4 to 255, lakukan proses berikut For N = 4 To 255 'X = T[n-4] + T[n-1] X = FAddBiner(T(N 4), T(N - 1), 32) 'T[n] = X>>3 XOR TT[X AND 7] T(N) = FOpBiner("XOR", FShiftRight(X, 3), TT(FBinerToDec(FOpBiner("AND", X, "111"))), 32)
L5
Next N '4. Untuk N = 0 to 22, lakukan proses berikut For N = 0 To 22 'T[n] = T[n] + T[n+89] T(N) = FAddBiner(T(N), T(N + 89), 32) Next N '5. Set nilai untuk variabel di bawah ini X = T(33) Z = FOpBiner("OR", T(59), FHexToBiner("01000001"), 32) Z = FOpBiner("AND", Z, FHexToBiner("FF7FFFFF"), 32) X = FAddBiner(FOpBiner("AND", X, FHexToBiner("FF7FFFFF"), 32), Z, 32) '6. Untuk T[0] ... T[255] For N = 0 To 255 'X = (X And FF7FFFFF) + Z X = FAddBiner(FOpBiner("AND", X, FHexToBiner("FF7FFFFF"), 32), Z, 32) 'T[n] = T[n] AND 00FFFFFF XOR X T(N) = FOpBiner("XOR", FOpBiner("AND", T(N), FHexToBiner("00FFFFFF"), 32), X, 32) Next N '7. Inisialisasi Nilai Untuk Beberapa Variabel Berikut T(256) = T(0) X = FOpBiner("AND", X, FDecToBiner(255), 32) '8. Untuk T[0] ... T[255] For N = 0 To 255 'Temp = (T[n XOR X] XOR X) AND 255 Temp = T(FBinerToDec(FOpBiner("XOR", FDecToBiner(N), X, 32))) Temp = FOpBiner("XOR", Temp, X, 32) Temp = FOpBiner("AND", Temp, FDecToBiner(255), 32) 'T[n] = T[Temp] T(N) = T(FBinerToDec(Temp)) 'T[X] = T[n+1]
T(FBinerToDec(X)) = T(N + 1) Next N End Sub 'PROSES PEMBENTUKAN KUNCI Public Sub GetWakeKEY(pcKunci As String, pnPutaran As Integer) Dim A() As String Dim B() As String Dim C() As String Dim D() As String Dim N As Integer Dim X As String ReDim A(pnPutaran) ReDim B(pnPutaran) ReDim C(pnPutaran) ReDim D(pnPutaran) '1. Inisialisasi nilai awal untuk A[0], B[0], C[0], D[0] ' Pecah kunci (128 bit) menjadi 4 kelompok X = "" For N = 1 To Len(pcKunci) X = X & FormatS(FDecToBiner(Asc(Mid(pc Kunci, N, 1))), "0", 8) Next N A(0) = Mid(X, 1, 32) B(0) = Mid(X, 33, 32) C(0) = Mid(X, 65, 32) D(0) = Mid(X, 97, 32)
1), 1), 1), 1),
End
'2. Putaran kunci For N = 1 To pnPutaran A(N) = FungsiM(A(N D(N - 1)) B(N) = FungsiM(B(N A(N)) C(N) = FungsiM(C(N B(N)) D(N) = FungsiM(D(N C(N)) Next N 'Bit Kunci strKunciBiner = D(N - 1) Sub
'FUNGSI M(X,Y) DARI REGISTER A, B, C DAN D Public Function FungsiM(pX As String, pY As String) As String Dim Temp As String Dim Temp1 As String 'Temp1 = X + Y
L6
Temp1 = FAddBiner(pX, pY, 32) 'Temp = Temp1 Shift >> 8
kali
Temp = FShiftRight(Temp1, 8)
'Temp1 = (X + Y) And 255 Temp1 = FBinerToDec(FOpBiner("AND", Temp1, "11111111")) 'Temp1 = T[(X + Y) And 255)] Temp1 = T(Val(Temp1)) 'di-XOR T(X + Y) Temp = FOpBiner("XOR", Temp, Temp1, 32) 'Kembalikan nilai FungsiM = Temp End Function 'PROSES ENKRIPSI Public Sub WAKEEncryption(pcEnkripsi As String) Dim X As String Dim X1 As String Dim X2 As String Dim N As Integer Dim cHasil As String 'Text Enkripsi strPlain = pcEnkripsi 'Text-enkripsi dalam bentuk biner X = "" For N = 1 To Len(strPlain) X = X & FormatS(FDecToBiner(Asc(Mid(st rPlain, N, 1))), "0", 8) Next N X1 = "": X2 = "": cHasil = "" For N = 1 To Len(X) Step 8 'Kunci X1 = Mid(strKunciBiner, (N Mod 32), 8) 'Hasil - XOR dengan kunci X2 = FOpBiner("XOR", Mid(X, N, 8), X1, 8) 'Simpan ke karakter cHasil = cHasil & Chr(FBinerToDec(X2)) Next N 'Return Cipher Text strCipher = cHasil End Sub
'PROSES DEKRIPSI Public Sub WAKEDecryption(pcDekripsi As String) Dim X As String Dim X1 As String Dim X2 As String Dim N As Integer Dim cHasil As String 'Text Dekripsi strCipher = pcDekripsi 'Text-Dekripsi dalam bentuk biner X = "" For N = 1 To Len(strCipher) X = X & FormatS(FDecToBiner(Asc(Mid(st rCipher, N, 1))), "0", 8) Next N X1 = "": X2 = "": cHasil = "" For N = 1 To Len(X) Step 8 'Kunci X1 = Mid(strKunciBiner, (N Mod 32), 8) 'Hasil - XOR dengan kunci X2 = FOpBiner("XOR", Mid(X, N, 8), X1, 8) 'Simpan ke karakter cHasil = cHasil & Chr(FBinerToDec(X2)) Next N 'Return Plain Text strPlain = cHasil End Sub