請提供份rsa加密演算法的vb原始碼

時間 2021-12-25 01:36:40

1樓:鵬凌三千

rem ****** rsa program

rem (c) w.buchanan

rem jan 2002

function check_prime(byval val as long) as boolean

dim primes

primes = array(1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397)

check_prime = false

for i = 0 to 78

if (val = primes(i)) then

prime = true

end if

next i

check_prime = prime

end function

function decrypt(byval c, byval n, byval d as long)

dim i, g, f as long

on error goto errorhandler

if (d mod 2 = 0) then

g = 1

else

g = c

end if

for i = 1 to d / 2

f = c * c mod n

g = f * g mod n

next i

decrypt = g

exit function

errorhandler:

select case err.number ' evaluate error number.

case 6

status.text = "calculation overflow, please select smaller values"

case else

status.text = "calculation error"

end select

end function

function getd(byval e as long, byval phi as long) as long

dim u(3) as long

dim v(3) as long

dim q, temp1, temp2, te*** as long

u(0) = 1

u(1) = 0

u(2) = phi

v(0) = 0

v(1) = 1

v(2) = e

while (v(2) <> 0)

q = int(u(2) / v(2))

temp1 = u(0) - q * v(0)

temp2 = u(1) - q * v(1)

te*** = u(2) - q * v(2)

u(0) = v(0)

u(1) = v(1)

u(2) = v(2)

v(0) = temp1

v(1) = temp2

v(2) = te***

wend

if (u(1) < 0) then

getd = (u(1) + phi)

else

getd = u(1)

end if

end function

function gete(byval phi as long) as long

dim great, e as long

great = 0

e = 2

while (great <> 1)

e = e + 1

great = get_common_denom(e, phi)

wend

gete = e

end function

function get_common_denom(byval e as long, byval phi as long)

dim great, temp, a as long

if (e > phi) then

while (e mod phi <> 0)

temp = e mod phi

e = phi

phi = temp

wend

great = phi

else

while (phi mod e <> 0)

a = phi mod e

phi = e

e = a

wend

great = e

end if

get_common_denom = great

end function

private sub show_primes()

status.text = "1"

no_primes = 1

for i = 2 to 400

prime = true

for j = 2 to (i / 2)

if ((i mod j) = 0) then

prime = false

end if

next j

if (prime = true) then

no_primes = no_primes + 1

status.text = status.text + ", " + str(i)

end if

next i

status.text = status.text + vbcrlf + "number of primes found:

" + str(no_primes)

end sub

private sub command1_click()

dim p, q, n, e, phi, d, m, c as long

p = text1.text

q = text2.text

if (check_prime(p) = false) then

status.text = "p is not a prime or is too large, please re-enter"

elseif (check_prime(q) = false) then

status.text = "q is not a prime or is too large, please re-enter"

else

n = p * q

text3.text = n

phi = (p - 1) * (q - 1)

e = gete((phi))

d = getd((e), (phi))

text4.text = phi

text5.text = d

text6.text = e

m = text7.text

c = (m ^ e) mod n

text8.text = c

m = decrypt(c, n, d)

text9.text = m

label12.caption = "decrypt key =<" + str(d) + "," + str(n) + ">"

label13.caption = "encrypt key =<" + str(e) + "," + str(n) + ">"

end if

end sub

private sub command2_click()

endend sub

private sub command3_click()

frmbrowser.show

end sub

private sub command4_click()

call show_primes

end sub

對稱加密演算法和非對稱加密演算法的區別是什麼

一 對稱加密 symmetric cryptography 對稱加密是最快速 最簡單的一種加密方式,加密 encryption 與解密 decryption 用的是同樣的金鑰 secret key 這種方法在密碼學中叫做對稱加密演算法。對稱加密有很多種演算法,由於它效率很高,所以被廣泛使用在很多加密...

著名的可逆的加密演算法有哪些,常用的對稱加密演算法有哪些?

陳說教育 1,des data encryption standard 對稱演算法,資料加密標準,速度較快,適用於加密大量資料的場合。2,3des triple des 是基於des的對稱演算法,對一塊資料用三個不同的金鑰進行三次加密,強度更高。3,rc2和rc4 對稱演算法,用變長金鑰對大量資料進...

什麼是對稱加密演算法?請舉例,常用的對稱加密演算法有哪些?

對稱加密演算法是指 加密和解密都用同一個金鑰,常見的有 3des演算法,blowfish演算法,rc5演算法等 常用的對稱加密演算法有哪些?對稱加密演算法用來對敏感資料等資訊進行加密,常用的演算法包括 des data encryption standard 資料加密標準,速度較快,適用於加密大量資...