Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Function tidak jalan....

Halo semuanya.....ane br bljr fungsi di VB nicg, tolong pencerahannya!

Disini ane membuat suatu program yang membangkitkan kunci secara random, untuk imlplementasi dari Algoritma Kriptografi Elgamal. Berikut kutipan dari scriptnya:
=================================
Private Sub CmdKunci_Click()
p = primaaman()
alfa = primitif(p)
a = Rnd(p - 3) + 1
beta = fastexp(alfa, a, p)
Txtp.Text = p ' Print (p)
Txtalfa.Text = alfa ' Print (alfa)
Txtbeta.Text = beta ' Print (beta)
Txta.Text = a ' Print (a)
End Sub
=================================

'Fungsi Mencari Bilangan Prima Aman
Function primaaman() As Long
Dim rand As Long
Randomize
Do
Do
rand = Rnd(2000) + 128 + 1
If rand Mod 2 = 0 Then rand = rand + 1
Loop Until cekprima(rand) = 1
p = (2 * rand) + 1
Loop Until cekprima(p) = 1
primaaman = p
End Function

===========================================
'Fungsi Untuk Mencari Elemen Primitif acak
Function primitif(ByVal p As Long) As Long
Dim alfa As Long
Do
Randomize
alfa = Rnd(p - 2) + 1
Loop Until cekprimitif(alfa, p) = 1
primitif = alfa
End Function

===========================================
'{Fungsi Untuk Mengecek Elemen Primitif}
Function cekprimitif(ByVal alfa As Long, ByVal p As Long) As Integer
Dim b, q As Long
q = (p - 1) \ 2
b = fastexp(alfa, 2, p)
If b = 1 Then
cekprimitif = 0
Else
b = fastexp(alfa, q, p)
End If
If b = 1 Then
cekprimitif = 0
Else
cekprimitif = 1
End If
End Function

===========================================
'{Fungsi Pengecekan Bilangan Prima}
Function cekprima(ByVal a As Long) As Integer
Dim b, c As Long
b = 1
Do
b = b + 1
c = a Mod b
Loop Until c = 0
If a = b Then
cekprima = 1
Else
cekprima = 0
End If
End Function

===========================================
'{Fungsi Pengecekan Bilangan Prima Aman}
Function cekprimaaman(ByVal p As Long) As Integer
Dim Y As Long
If cekprima(p) = 1 Then
Y = p - 1
Y = Y \ 2
If cekprima(Y) = 1 Then
cekprimaaman = 1
End If
If cekprima(Y) = 0 Then
cekprimaaman = 0
End If

Else
cekprimaaman = 0
End If
End Function


===========================================
'{Metode Fast Exponentiation}
Function fastexp(ByVal r As Long, ByVal s As Long, ByVal t As Long) As Long
Dim X, mtemp, atemp As Long
atemp = r
mtemp = s
X = 1
Do While (mtemp <> 0)

Do While (mtemp Mod 2 = 0)
mtemp = mtemp \ 2
atemp = (atemp * atemp) Mod t
Loop
mtemp = mtemp - 1
X = (X * atemp) Mod t
Loop
If X < 0 Then
X = (X + t) Mod t
End If
fastexp = X
End Function
===========================================

Tp pas diRun, programnya 'gak jalan tapi 'gak ada error lagi. Dimana salah nya yach.... Program ini ane konvert dari pascal.
Tolong pencerahannya, thx b4.

Comments

Sign In or Register to comment.