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

2021-12-25 01:38:34 字數 5231 閱讀 1350

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

請提供600的鬼故事,請提供一個600 1000字的鬼故事

青丘 鬼話連篇 每天一個鬼故事,可以任選擇一。個片段。落 1000字左右的恐怖鬼故事!1000字左右的恐怖鬼故事 話說四川一座大學,位與城市郊外,平時就流傳著不少令人奇怪的不可思議的故事。有一個女生寢室,住著7個女生,平日裡相安無事,但是有一晚,住在下鋪的一個女生 我們暫且叫她小萍吧 怎麼也睡不著。...

請提供週記,請提供一篇週記 200 300字

初一的感覺 似水流年,今天的我們已不再是在草地裡玩過家家的小朋友 今天的我們已不再是大聲朗讀 床前明月光 的小學生 今天的我們已經告別童年,走向青春。帶著對未來的憧憬,我們來到了人大附中,走進了初一生活。開學已經一個月了,對新的環境有了一定的瞭解。面對初一生活也有許多感受。上初一了,第一個感覺是新鮮...

請提供家庭類美劇

人人都愛雷蒙德 老爸老媽的浪漫史 好漢兩個半 這個有小孩 推薦 雪山鎮 和 天賜 兩部溫馨的美劇,其中也不乏搞笑,不由得讓你觸景生情,看完心裡好甜蜜。雪山鎮 有個不幸的開頭但有個溫暖的結局。天賜 是一部沒有結局的美劇,好像不會再拍了,這點太遺憾,但內容真的很精彩。如果你想要溫馨和感動,值得一看!成長...