Penulis Publikasi (ArtikelJurnaldll) Waktu dipublikasi - Analisis Kinerja Algoritma Rabin dan Rivest Shamir Adleman ( RSA ) pada Kriptografi

LAMPIRAN 1 : Daftar Publikasi Ilmiah

  

DAFTAR PUBLIKASI ILMIAH PENULIS ( TESIS )

No. Judul Artikel Penulis Publikasi (Artikel/Jurnal/dll)

  Waktu dipublikasi Tempat

  LAMPIRAN 2 : Listing Program Module

  Public Declare Function GetTickCount Lib "kernel32" () As Long Public Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hwndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Public Const HWND_TOPMOST = -1 Public Const HWND_NOTOPMOST = -2 Public Const SWP_NOSIZE = &H1 Public Const SWP_NOMOVE = &H2 Private Type Configuration DelEncryptedFileAfterSave As Boolean DelSourceAfterSave As Boolean Mode As Byte Mask As Boolean Directory As String End Type Public Cfg As Configuration Public KeyInput As String, SeedInput As String Public MsgButton As Byte Public Sukses As Boolean Public nP As Double Public nQ As Double Public nN As Double Public nT As Double Public nE As Double Public nD As Double Public TampilLaporan As Boolean 'Pengubahan desimal menjadi biner

  Public Function FDec2Biner(pnAngka As Double, Optional pnLength As Integer = -1) As String Dim nLoop As Double Dim nHasilBagi As Double Dim nSisaBagi As Double Dim cBiner1 As String Dim cBiner2 As String nHasilBagi = pnAngka While nHasilBagi <> 0 nSisaBagi = FMod(nHasilBagi, 2) cBiner1 = cBiner1&Format(nSisaBagi)'format=CStr nHasilBagi = FDiv(nHasilBagi, 2) 'div \Wend If cBiner1 = "" Then cBiner1 = "0" 'Ambil Terbalik For nLoop = Len(cBiner1) To 1 Step -1 cBiner2 = cBiner2 & Mid(cBiner1, nLoop, 1) Next nLoop If pnLength = -1 Then 'Angka Biner FDec2Biner = cBiner2 Else If Len(cBiner2) <= pnLength Then 'Angka Biner Kurang dari pnLength FDec2Biner = String(pnLength - Len(cBiner2), "0") & cBiner2 Else 'Angka Biner Melebihi pnLength FDec2Biner = Left(cBiner2, pnLength) End If

  End If End Function 'Pengubahan biner menjadi desimal Public Function FBiner2Dec(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)) 'mengubah index pcText terkanan menjadi 0 End If Next nLoop 'Angka Desimal FBiner2Dec = nHasil End Function Public Function FMod(pnA1 As Double, pnA2 As Double) As Double Dim nMod As Double nMod = pnA1 / pnA2 FMod = pnA1 - (pnA2 * Int(nMod)) 'mendukung modulo bilangan negatif End Function Public Function FDiv(pnA1 As Double, pnA2 As Double) As Double Dim nDiv As Double nDiv = pnA1 / pnA2 FDiv = Int(nDiv) End Function Public Function FXORBiner(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, sehingga panjang pcText1 & pcText2 sesuai dengan pnByte If Len(pcText1) > Len(pcText2) Then nByte1 = Len(pcText1) Else nByte1 = Len(pcText2) End If End If cText1 = FormatStr(pcText1, "0", nByte1) 'tambahkan karakter 0 di depan pcText1 cText2 = FormatStr(pcText2, "0", nByte1) 'tambahkan karakter 0 di depan pcText2 For nF = 1 To nByte1 cXOR = cXOR & IIf(Mid(cText1, nF, 1) = Mid(cText2, nF, 1), "0", "1") 'Sama dengan XOR Next nF 'Hasil XOR cHasilXOR = FormatStr(cXOR, "0", pnByte) 'tambahkan karakter 0 di depan cXOR sesuai dengan panjang pnByte FXORBiner = cHasilXOR End Function Public Function FormatStr(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 tambahkan karakter 0 di depan pcText sesuai pnLength FormatStr = String(pnLength - Len(pcText), pcZeroText) & pcText Else FormatStr = pcText End If End Function 'Biner ke heksa Public Function FBiner2Hex(pcText As String) As String Dim i As Integer Dim cText As String cText = IIf(Len(pcText) = 0, "0000", pcText) i = Len(cText) Mod 4 'panjang pcText diset menjadi kelipatan empat If i <> 0 Then cText = FormatStr(cText, "0", CLng(Len(cText) + 4 - i)) For i = 1 To Len(cText) Step 4 FBiner2Hex = FBiner2Hex & Hex(FBiner2Dec(Mid(cText, i, 4))) Next i End Function 'Heksa ke desimal Public Function FHex2Dec(pcText As String) As Double Dim i As Integer For i = 1 To Len(pcText) Select Case Mid(pcText, i, 1) 'ambil dari kiri Case "1" To "9": FHex2Dec = FHex2Dec + CDec(Mid(pcText, i, 1)) * 16 ^ (Len(pcText) - i) Case "A", "a": FHex2Dec = FHex2Dec + 10 * 16 ^ (Len(pcText) - i) Case "B", "b": FHex2Dec = FHex2Dec + 11 * 16 ^ (Len(pcText) - i) Case "C", "c": FHex2Dec = FHex2Dec + 12 * 16 ^ (Len(pcText) - i) Case "D", "d": FHex2Dec = FHex2Dec + 13 * 16 ^ (Len(pcText) - i) Case "E", "e": FHex2Dec = FHex2Dec + 14 * 16 ^ (Len(pcText) - i) Case "F", "f": FHex2Dec = FHex2Dec + 15 * 16 ^ (Len(pcText) - i) End Select

  Next i End Function 'Inverse functions Public Function Inverse(a As Double) As Double Dim G0 As Double, G1 As Double, G2 As Double, V0 As Double, V1 As Double, V2 As Double, Y As Double, n As Double n = 4294967295# G0 = n G1 = a V0 = 0 V1 = 1 While (G1 <> 0) Y = Int(G0 / G1) G2 = G0 - Y * G1 G0 = G1 G1 = G2 V2 = V0 - Y * V1 V0 = V1 V1 = V2 Wend If (V0 >= 0) Then Inverse = V0 Else Inverse = V0 + n End If End Function Public Function FHex2Biner(pcHex As String) As String Dim nH As Integer Dim cHasil As String For nH = 1 To Len(pcHex) cHasil = cHasil & FDec2Biner(FHex2Dec(Mid(pcHex, nH, 1)), 4) Next nH FHex2Biner = cHasil End Function 'Least Significant Bit Public Function LSB(pcBit As String) As String LSB = Right(pcBit, 1) End Function 'Penjumlahan 2 buah biner Public Function FAddBin(pcBiner1 As String, pcBiner2 As String) As String Dim nMaxLen As Long Dim nF As Integer Dim cBiner1 As String Dim cBiner2 As String Dim cBit1 As String Dim cBit2 As String Dim nCarry As Byte Dim nHasil As Byte Dim cHasil As String nMaxLen = IIf(Len(pcBiner1) > Len(pcBiner2), Len(pcBiner1), Len(pcBiner2)) cBiner1 = FormatStr(pcBiner1, "0", nMaxLen) cBiner2 = FormatStr(pcBiner2, "0", nMaxLen) For nF = 1 To nMaxLen cBit1 = Mid(cBiner1, nMaxLen - nF + 1, 1) cBit2 = Mid(cBiner2, nMaxLen - nF + 1, 1) nHasil = CByte(cBit1) + CByte(cBit2) + nCarry nCarry = nHasil \ 2 nHasil = nHasil Mod 2 cHasil = nHasil & cHasil Next nF

  FAddBin = nCarry & cHasil End Function 'Pengurangan 2 buah biner dengan hasil bilangan positif Public Function FSubBin(pcBiner1 As String, pcBiner2 As String) As String Dim nMaxLen As Long Dim nF As Integer Dim cBiner1 As String Dim cBiner2 As String Dim cBit1 As String Dim cBit2 As String Dim nBorrow As Byte Dim nHasil As Byte Dim cHasil As String nMaxLen = IIf(Len(pcBiner1) > Len(pcBiner2), Len(pcBiner1), Len(pcBiner2)) cBiner1 = FormatStr(pcBiner1, "0", nMaxLen) cBiner2 = FormatStr(pcBiner2, "0", nMaxLen) For nF = 1 To nMaxLen cBit1 = Mid(cBiner1, nMaxLen - nF + 1, 1) cBit2 = Mid(cBiner2, nMaxLen - nF + 1, 1) If CByte(cBit1) >= (CByte(cBit2) + nBorrow) Then nHasil = CByte(cBit1) - CByte(cBit2) - nBorrow nBorrow = 0 Else nHasil = CByte(cBit1) + 2 - CByte(cBit2) - nBorrow nBorrow = 1 End If cHasil = nHasil & cHasil Next nF FSubBin = cHasil End Function

  'Perkalian bit dengan biner Public Function FMulBit_Bin(pcBit As String, pcBiner As String) As String Dim nM As Integer Dim cHsl As String Dim cBitBiner As String For nM = 1 To Len(pcBiner) cBitBiner = Mid(pcBiner, Len(pcBiner) - nM + 1, 1) cHsl = (CByte(cBitBiner) * CByte(pcBit)) & cHsl Next nM FMulBit_Bin = cHsl End Function 'Perkalian 2 buah biner Public Function FMulBin(pcBiner1 As String, pcBiner2 As String) As String Dim nMaxLen As Long Dim nF As Integer Dim cBiner1 As String Dim cBiner2 As String Dim cBit1 As String Dim nCarry As Byte Dim nHasil As Byte Dim cHasil As String Dim cRslt As String cBiner1 = FBuangNolKiri(pcBiner1) cBiner2 = FBuangNolKiri(pcBiner2) nMaxLen = IIf(Len(cBiner1) > Len(cBiner2), Len(cBiner1), Len(cBiner2)) cBiner1 = FormatStr(cBiner1, "0", nMaxLen) cBiner2 = FormatStr(cBiner2, "0", nMaxLen) For nF = 1 To nMaxLen cBit1 = Mid(cBiner1, nMaxLen - nF + 1, 1) cRslt = FMulBit_Bin(cBit1, cBiner2) & String(nF - 1, "0") cHasil = FAddBin(cHasil, cRslt)

  Next nF FMulBin = cHasil End Function 'Buang bit "0" yang berlebihan di sebelah kiri Public Function FBuangNolKiri(pcBiner As String) As String Dim cBiner As String cBiner = pcBiner While Left(cBiner, 1) = "0" cBiner = Right(cBiner, Len(cBiner) - 1) Wend FBuangNolKiri = cBiner End Function 'Modulo 2 buah biner Public Function FModBin(pcBiner1 As String, pcBiner2 As String) As String Dim nF As Integer Dim cBit1 As String Dim nSisa As Double Dim cSisa As String Dim nBil1 As Double Dim nPos As Integer Dim cBiner2 As String cBit1 = Mid(pcBiner1, 1, Len(pcBiner2)) nPos = Len(pcBiner2) cBit1 = FBuangNolKiri(cBit1) cBiner2 = FBuangNolKiri(pcBiner2) Do If (Len(cBiner2) > Len(cBit1)) Or _ ((Len(cBiner2) = Len(cBit1)) And (cBit1 < cBiner2)) Then 'Jika bil I lebih kecil dr bil II (bil mod) cSisa = cBit1 Else cSisa = FSubBin(cBit1, cBiner2) End If nPos = nPos + 1 If nPos <= Len(pcBiner1) Then cBit1 = cSisa & Mid(pcBiner1, nPos, 1) cBit1 = FBuangNolKiri(cBit1) Loop Until nPos > Len(pcBiner1) FModBin = cSisa End Function Public Function RSAEncrypt(ByVal pcPesan As String, ByVal pnE As Double, ByVal pnN As Double) As String Dim nB As Integer Dim cBiner As String Dim nI As Long Dim ArrM() As String Dim ArrM1() As String Dim ArrM2() As Double Dim ArrC() As Double Dim cTemp1 As String Dim nIndeks As Integer 'Hitung nilai b nB = 1 While (2 ^ nB) < pnN nB = nB + 1 Wend If (2 ^ nB) > pnN Then nB = nB - 1 cBiner = "" ReDim ArrM(Len(pcPesan)) 'Ubah pesan ke bentuk ASCII Code Biner For nI = 1 To Len(pcPesan) ArrM(nI) = FDec2Biner(Asc(Mid(pcPesan, nI, 1)), 8)

cBiner = cBiner & ArrM(nI) Next 'Kelompokkan bit pesan menjadi b bit subblok ReDim ArrM1(0) ReDim ArrM2(0) nIndeks = 0 For nI = 1 To Len(cBiner) Step nB nIndeks = nIndeks + 1 ReDim Preserve ArrM1(nIndeks) ReDim Preserve ArrM2(nIndeks) ArrM1(nIndeks) = Mid(cBiner, nI, nB) If Len(ArrM1(nIndeks)) < nB Then ArrM1(nIndeks) = ArrM1(nIndeks) & FString(nB - Len(ArrM1(nIndeks)), "0") ArrM2(nIndeks) = FBiner2Dec(ArrM1(nIndeks)) Next 'Hitung nilai ciphertext C cTemp1 = "" ReDim ArrC(UBound(ArrM1)) For nI = 1 To UBound(ArrM1) ArrC(nI) = FastExp(ArrM2(nI), pnE, pnN) cTemp1 = cTemp1 & Format(ArrC(nI), FString(Len(CStr(pnN)), "0")) Next RSAEncrypt = cTemp1 End Function Public Function RSADecrypt(ByVal pcCipher As String, ByVal pnD As Double, ByVal pnN As Double) As String Dim nB As Integer Dim nB1 As Integer Dim nI As Long Dim nJ As Long Dim ArrM() As String

  Dim ArrM1() As String Dim ArrC() As Double Dim ArrC1() As String Dim cTemp As String Dim cTemp1 As String Dim cCipher As String Dim nTemp As Integer cCipher = pcCipher nB1 = Len(CStr(pnN)) 'Hitung nilai b nB = 1 While (2 ^ nB) < pnN nB = nB + 1 Wend If (2 ^ nB) > pnN Then nB = nB

  • – 1 'Kelompokkan menjadi subblok cipher dengan panjang b bit ReDim ArrC1(0) ReDim ArrC(0) nJ = 0 For nI = 1 To Len(cCipher) Step nB1 nJ = nJ + 1 ReDim Preserve ArrC1(nJ)

  ReDim Preserve ArrC(nJ) ArrC1(nJ) = Mid(cCipher, nI, nB1) ArrC(nJ) = Val(ArrC1(nJ)) Next 'Hitung nilai plaintext M ReDim ArrM(UBound(ArrC1)) For nI = 1 To UBound(ArrC1) ArrM(nI) = FastExp(ArrC(nI), pnD, pnN) Next

  'Konversi plaintext ke bentuk biner ReDim ArrM1(UBound(ArrM)) cTemp = "" For nI = 1 To UBound(ArrM) ArrM1(nI) = FDec2Biner(CDbl(ArrM(nI)), nB) cTemp = cTemp & ArrM1(nI) Next 'Kelompokkan menjadi blok of 8 cTemp1 = "" For nI = 1 To Len(cTemp) Step 8 nTemp = FBiner2Dec(Mid(cTemp, nI, 8)) If nTemp > 0 Then cTemp1 = cTemp1 & Chr(nTemp) Next RSADecrypt = cTemp1 End Function Public Sub GenerateRSAKey() Dim nI As Double Dim nDigit As Byte Dim nMax As Double Do 'Generate kunci Randomize Timer nDigit = 4 + Int(Rnd() * 4) nP = RabinMiller(nDigit) nQ = RabinMiller(nDigit) nN = nP * nQ nT = (nP - 1) * (nQ - 1) If nP > nQ Then nMax = nP

  Else nMax = nQ End If nD = Int(Rnd() * (nT - 1 - nMax)) + nMax + 1 If FGCD(nD, nT) = 1 And nD > nMax + 1 And nD < nT - 1 Then nE = ExtendedEuclidean(nD, nT) Loop Until FGCD(nD, nT) = 1 And nD > nMax + 1 And nD < nT - 1 And RSADecrypt(RSAEncrypt("A", nE, nP * nQ), nD, nP * nQ) = "A" nE = ExtendedEuclidean(nD, nT) End Sub Public Sub GenerateRabinKey() Do Randomize Timer nDigit = 2 + Int(Rnd() * 2) Do nP = RabinMiller(nDigit) Loop Until FMod(nP, 4) = 3 Do nQ = RabinMiller(nDigit) Loop Until FMod(nQ, 4) = 3 nN = nP * nQ Loop Until RabinDecrypt(RabinEncrypt("A", nN), nP, nQ, nN) = "A" End Sub Public Function RabinEncrypt(pcPesan As String, pnN As Double) As String Dim nB As Integer Dim cBiner As String Dim nI As Long Dim ArrM() As String Dim ArrM1() As String Dim ArrM2() As Double Dim ArrC() As Double

  Dim cTemp1 As String Dim nIndeks As Integer 'Hitung nilai b nB = 1 While (2 ^ nB) < pnN nB = nB + 1 Wend If (2 ^ nB) > pnN Then nB = nB - 1 cBiner = "" ReDim ArrM(Len(pcPesan)) 'Ubah pesan ke bentuk ASCII Code Biner For nI = 1 To Len(pcPesan) ArrM(nI) = FDec2Biner(Asc(Mid(pcPesan, nI, 1)), 8) cBiner = cBiner & ArrM(nI) Next 'Kelompokkan bit pesan menjadi b bit subblok 'Agar subblok dapat dikenali pada saat dekripsi, sisipkan bit pengenal didepan ReDim ArrM1(0) ReDim ArrM2(0) nIndeks = 0 For nI = 1 To Len(cBiner) Step nB - 4 nIndeks = nIndeks + 1 ReDim Preserve ArrM1(nIndeks) ReDim Preserve ArrM2(nIndeks) ArrM1(nIndeks) = "1111" & Mid(cBiner, nI, nB - 4) If Len(ArrM1(nIndeks)) < nB Then ArrM1(nIndeks) = ArrM1(nIndeks) & FString(nB - Len(ArrM1(nIndeks)), "0") ArrM2(nIndeks) = FBiner2Dec(ArrM1(nIndeks)) Next 'Hitung nilai ciphertext C cTemp1 = "" ReDim ArrC(UBound(ArrM1)) For nI = 1 To UBound(ArrM1) ArrC(nI) = FastExp(ArrM2(nI), 2, pnN) cTemp1 = cTemp1 & Format(ArrC(nI), FString(Len(CStr(pnN)), "0")) Next RabinEncrypt = cTemp1 End Function Public Function RabinDecrypt(pcCipher As String, pnP As Double, pnQ As Double, pnN As Double) As String On Error GoTo errDecrypt Dim nB As Integer Dim nB1 As Integer Dim nI As Long Dim nJ As Long Dim ArrM() As String Dim ArrM1() As String Dim ArrC() As Double Dim ArrC1() As String Dim cTemp As String Dim cTemp1 As String Dim cCipher As String Dim nTemp As Integer Dim nArrM1() As Double Dim nArrM2() As Double Dim nArrM3() As Double Dim nArrM4() As Double Dim nNilaiA As Double Dim nNilaiB As Double Dim nM1() As Double Dim nM2() As Double

  Dim nM3() As Double Dim nM4() As Double Dim cBitNilai1 As String Dim cBitNilai2 As String Dim cBitNilai3 As String Dim cBitNilai4 As String cCipher = pcCipher nB1 = Len(CStr(pnN)) 'Hitung nilai b nB = 1 While (2 ^ nB) < pnN nB = nB + 1 Wend If (2 ^ nB) > pnN Then nB = nB - 1 'Kelompokkan menjadi subblok cipher dengan panjang b bit ReDim ArrC1(0) ReDim ArrC(0) nJ = 0 For nI = 1 To Len(cCipher) Step nB1 nJ = nJ + 1 ReDim Preserve ArrC1(nJ) ReDim Preserve ArrC(nJ) ArrC1(nJ) = Mid(cCipher, nI, nB1) ArrC(nJ) = Val(ArrC1(nJ)) Next 'Hitung nilai plaintext M nNilaiA = pnQ * ExtendedEuclidean(pnQ, pnP) nNilaiB = pnP * ExtendedEuclidean(pnP, pnQ) ReDim nArrM1(UBound(ArrC1)) ReDim nArrM2(UBound(ArrC1))

  ReDim nArrM3(UBound(ArrC1)) ReDim nArrM4(UBound(ArrC1)) ReDim nM1(UBound(ArrC1)) ReDim nM2(UBound(ArrC1)) ReDim nM3(UBound(ArrC1)) ReDim nM4(UBound(ArrC1)) ReDim ArrM(UBound(ArrC1)) ReDim ArrM1(UBound(ArrC1)) For nI = 1 To UBound(ArrC1) nArrM1(nI) = FastExp(ArrC(nI), (pnP + 1) / 4, pnN) nArrM2(nI) = FModulus(pnP - FastExp(ArrC(nI), (pnP + 1) / 4, pnN), pnP) nArrM3(nI) = FastExp(ArrC(nI), (pnQ + 1) / 4, pnN) nArrM4(nI) = FModulus(pnQ - FastExp(ArrC(nI), (pnQ + 1) / 4, pnN), pnQ) nM1(nI) = FMod(nNilaiA * nArrM1(nI) + nNilaiB * nArrM3(nI), pnN) nM2(nI) = FMod(nNilaiA * nArrM1(nI) + nNilaiB * nArrM4(nI), pnN) nM3(nI) = FMod(nNilaiA * nArrM2(nI) + nNilaiB * nArrM3(nI), pnN) nM4(nI) = FMod(nNilaiA * nArrM2(nI) + nNilaiB * nArrM4(nI), pnN) '======================================= 'Cek bit pengenal di depan cBitNilai1 = FDec2Biner(nM1(nI), nB) cBitNilai2 = FDec2Biner(nM2(nI), nB) cBitNilai3 = FDec2Biner(nM3(nI), nB) cBitNilai4 = FDec2Biner(nM4(nI), nB) If Left(cBitNilai1, 4) = "1111" Then ArrM(nI) = nM1(nI) ElseIf Left(cBitNilai2, 4) = "1111" Then ArrM(nI) = nM2(nI) ElseIf Left(cBitNilai3, 4) = "1111" Then ArrM(nI) = nM3(nI) ElseIf Left(cBitNilai4, 4) = "1111" Then ArrM(nI) = nM4(nI) End If

  '======================================= Next 'Konversi plaintext ke bentuk biner cTemp = "" For nI = 1 To UBound(ArrM) ArrM1(nI) = FDec2Biner(CDbl(ArrM(nI)), nB) cTemp = cTemp & Right(ArrM1(nI), nB - 4) Next 'Kelompokkan menjadi blok of 8 cTemp1 = "" For nI = 1 To Len(cTemp) Step 8 nTemp = FBiner2Dec(Mid(cTemp, nI, 8)) If nTemp > 0 Then cTemp1 = cTemp1 & Chr(nTemp) Next RabinDecrypt = cTemp1 Exit Function errDecrypt: RabinDecrypt = "" End Function Public Function FString(ByVal pnValue As Double, ByVal pcChar As String) As String Dim nI As Double Dim cTemp As String cTemp = "" For nI = 1 To pnValue cTemp = cTemp & pcChar Next FString = cTemp End Function

  'Algoritma Fast Exponentiation - (A^B) mod C Public Function FastExp(ByVal a As Double, ByVal B As Double, ByVal C As Double) As Double Dim Product As Double Dim A1 As Double Dim B1 As Double A1 = a B1 = B Product = 1 While (B1 <> 0) While FMod(B1, 2) = 0 B1 = FDiv(B1, 2) A1 = FMod(A1 * A1, C) Wend B1 = B1 - 1 Product = FMod(Product * A1, C) Wend FastExp = Product End Function 'Pembangkitan bilangan prima dengan metode Rabin Miller sebesar nDigit Public Function RabinMiller(ByVal nDigit As Long) Dim bPrima As Boolean Dim nRandom As Long Dim nTotal As Integer Dim nA As Long Dim BTest80 As Boolean bPrima = False nTotal = 0 While bPrima = False nTotal = nTotal + 1 'Tentukan jumlah digit

  Randomize Timer nRandom = (10 ^ (nDigit - 1)) + Int(Rnd() * (Val(FString(nDigit, "9")) - (10 ^ (nDigit - 1)))) 'Angka Genap -> ubah menjadi ganjil If nRandom Mod 2 = 0 Then nRandom = nRandom + 1 'Test 80 persen BTest80 = Test80P(nRandom) If BTest80 Then '***--- VALIDASI ---*** If nRandom <= 1 Then bPrima = False ElseIf nRandom = 2 Then 'Bilangan Prima bPrima = True Else '***--- BANGKITKAN BILANGAN ACAK A ---*** If nRandom > 16 Then While ((nA = 0) Or (nA = 1)) Randomize Timer nA = Int(Rnd * 15) Wend Else While ((nA = 0) Or (nA = 1)) Randomize Timer nA = Int(Rnd * nRandom) Wend End If '***--- TEST PRIMA RABIN MILLER ---*** bPrima = TestPrima(nRandom, nA) End If End If 'Confirm

  If nTotal = 3000 Then RabinMiller = 0 Exit Function End If Wend RabinMiller = nRandom End Function 'GCD Function Public Function FGCD(ByVal a As Double, ByVal B As Double) As Double Dim P As Double Dim Q As Double Dim R As Double P = a Q = B While Q <> 0 R = FMod(P, Q) P = Q Q = R Wend FGCD = P End Function 'Algoritma Extended Euclidean Public Function ExtendedEuclidean(ByVal NilaiX As Double, ByVal pnValueN As Double) As Double Dim a(3, 2) As Double Dim nM As Double Dim nX As Double Dim nI As Integer Dim bSelesai As Boolean bSelesai = False

  'Bentuk Array a(1, 1) = pnValueN a(1, 2) = NilaiX 'Matriks Identitas a(2, 1) = 1 a(2, 2) = 0 a(3, 1) = 0 a(3, 2) = 1 While Not bSelesai 'Hitung nilai m nM = FDiv(a(1, 1), a(1, 2)) For nI = 1 To 3 'Hitung nilai x nX = a(nI, 1) - nM * a(nI, 2) 'Ubah nilai a(nI, 1) = a(nI, 2) a(nI, 2) = nX If nI = 1 And nX = 0 Then bSelesai = True End If Next nI Wend If a(3, 1) >= 0 Then ExtendedEuclidean = a(3, 1) Else ExtendedEuclidean = a(3, 1) + pnValueN End If End Function

  'Algoritma untuk tes bilangan prima (persentase 80%) Public Function Test80P(ByVal pnP As Long) As Boolean Dim nI As Long Dim bOK As Boolean bOK = True For nI = 2 To 255 If nI = 2 Or TestPrima(CDbl(nI), 2) Then If pnP <> nI And (pnP Mod CDbl(nI)) = 0 Then bOK = False Exit For End If End If Next nI Test80P = bOK End Function 'Algoritma untuk tes apakah suatu bilangan merp. prima atau tidak Public Function TestPrima(ByVal pnP As Long, ByVal pnA As Long) As Boolean 'Angka Genap If pnP Mod 2 = 0 Then TestPrima = False Exit Function End If 'Test Prima TestPrima = IsRabinMiller(pnP, pnA) End Function 'Algoritma untuk test Rabin-Miller Public Function IsRabinMiller(ByVal pnP As Long, ByVal pnA As Long) As Boolean Dim nTemp As Long Dim pnC As Long Dim pnB As Long

  Dim pnM As Long Dim pnJ As Long Dim pnZ As Long pnC = pnP

  • – 1 '------- CARI b nTemp = 0 While (pnC Mod (2 ^ nTemp)) = 0 And ((2 ^ nTemp) < pnP) nTemp = nTemp + 1 Wend pnB = nTemp - 1 '------- CARI m pnM = (pnC / (2 ^ pnB)) pnJ = 0 pnZ = FastExp(pnA, pnM, pnP) If (pnZ = 1) Or (pnZ = (pnP - 1)) Then

  IsRabinMiller = True Exit Function End If lAgain: If pnJ > 0 And pnZ = 1 Then IsRabinMiller = False Exit Function End If pnJ = pnJ + 1 If (pnJ < pnB) And (pnZ <> pnP - 1) Then pnZ = FastExp(pnZ, 2, pnP) GoTo lAgain End If If pnZ = (pnP - 1) Then

  IsRabinMiller = True Exit Function End If If pnJ = pnB And pnZ <> (pnP - 1) Then IsRabinMiller = False Exit Function End If End Function 'Fungsi Fermat untuk mengecek apakah sebuah bilangan merupakan bilangan prima atau bukan Public Function Fermat(ByVal pnM As Double) As Boolean Dim nA As Double Do nA = Int(Rnd() * 1000000) Loop Until FMod(nA, pnM) > 0 If FastExp(nA, pnM - 1, pnM) = 1 Then Fermat = True Else Fermat = False End If End Function Public Function GeneratePrime(ByVal nDigit As Long) As Double Dim nAngka As Double Do nAngka = Int(Rnd() * (10 ^ nDigit)) + 1 Loop Until Fermat(nAngka) GeneratePrime = nAngka End Function Public Function FModulus(ByVal pnValue1 As Double, ByVal pnValue2 As Double) As Double Dim nKali As Double

  Dim nHasil As Double If pnValue1 < 0 Then nKali = Abs(Int(pnValue1 / pnValue2)) nHasil = pnValue1 + (nKali * pnValue2) nHasil = (nHasil + pnValue2) Mod pnValue2 Else nHasil = pnValue1 Mod pnValue2 End If FModulus = nHasil End Function Public Function Coba(pcPesan As String) As String Dim cHasil As String Dim cEncrypt As String Call GenerateRSAKey cEncrypt = RSAEncrypt(pcPesan, nE, nN) cHasil = RSADecrypt(cEncrypt, nD, nN) Coba = cHasil End Function Public Function Coba1(pcPesan As String) As String Dim cHasil As String Dim cEncrypt As String Call GenerateRabinKey cEncrypt = RabinEncrypt(pcPesan, nN) cHasil = RabinDecrypt(cEncrypt, nP, nQ, nN) Coba1 = cHasil End Function 'Algoritma Euclid untuk mencari GCD Public Function GCD(a As Double, B As Double) As Double Dim P As Double

  Dim Q As Double Dim R As Double P = a Q = B While Q <> 0 R = FMod(P, Q) P = Q Q = R Wend GCD = P End Function