im q
Dim p
Randomize
Do
Do
'' 2 random primary numbers (0 to 1000)
Do
p = Rnd * 1000 \ 1
Loop While Not IsPrime(p)
Do
q = Rnd * 1000 \ 1
Loop While Not IsPrime(q)
'' n = product of 2 primes
Modulus = p * q \ 1
'' random decryptor (2 to n)
PrivateKey = Rnd * (Modulus - 2) \ 1 + 2
lLngPhi = (p - 1) * (q - 1) \ 1
PublicKey = Euler(lLngPhi, PrivateKey)
Loop While PublicKey = 0 Or PublicKey = 1
'' Loop if we can''t crypt/decrypt a byte
Loop While Not TestCrypt(255)
End Sub
Private Function TestCrypt(ByRef pBytData)
Dim lStrCrypted
lStrCrypted = Crypt(pBytData, PublicKey)
TestCrypt = Crypt(lStrCrypted, PrivateKey) = pBytData
End Function
Private Function Euler(ByRef pLngPHI, ByRef pLngKey)
&