我正在用Julia语言写RSA算法,这是我从 算法精解 C语言描述里抄写的代码
struct RSAPubKey
e::Int
n::Int
end
struct RSAPriKey
d::Int
n::Int
end
function modexp(a::Int, b::Int, n::Int)
y = 1
while b != 0
if b & 1 != 0
y = (y * a) % n
end
a = (a * a) % n
b = b >> 1
end
return y
end
function rsaencipher(plaintext::Int, pubkey::RSAPubKey)
ciphertext = modexp(plaintext, pubkey.e, pubkey.n)
return ciphertext
end
function rsadecipher(ciphertext::Int, prikey::RSAPriKey)
plaintext = modexp(ciphertext, prikey.d, prikey.n)
return plaintext
end
抄完我有点懵比,别人的RSA在线网站都是这样的
他是输入一个私匙密码后生成公匙和私匙,我这函数该怎么用啊??