首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 冲浪宝典-> 局域网
RSA加密算法在VB中的实现-.NET教程,VB.Net语言
作者:网友供稿 点击:298
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
-忘了摘自何处

rsa加密算法在vb中的实现


public key(1 to 3) as long
private const base64 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst
uvwxyz0123456789+/"

public sub genkey()
dim d as long, phi as long, e as long
dim m as long, x as long, q as long
dim p as long
randomize
on error goto top
top:
p = rnd * 1000 \ 1
if isprime(p) = false then goto top
sel_q:
q = rnd * 1000 \ 1
if isprime(q) = false then goto sel_q
n = p * q \ 1
phi = (p - 1) * (q - 1) \ 1
d = rnd * n \ 1
if d = 0 or n = 0 or d = 1 then goto top
e = euler(phi, d)
if e = 0 or e = 1 then goto top

x = mult(255, e, n)
if not mult(x, d, n) = 255 then
doevents
goto top
elseif mult(x, d, n) = 255 then
key(1) = e
key(2) = d
key(3) = n
end if
end sub

private function euler(byval a as long, byval b as long) as long
on error goto error2
r1 = a: r = b
p1 = 0: p = 1
q1 = 2: q = 0
n = -1
do until r = 0
r2 = r1: r1 = r
p2 = p1: p1 = p
q2 = q1: q1 = q
n = n + 1
r = r2 mod r1
c = r2 \ r1
p = (c * p1) + p2
q = (c * q1) + q2
loop
s = (b * p1) - (a * q1)
if s > 0 then
x = p1
else
x = (0 - p1) + a
end if
euler = x
exit function

error2:
euler = 0
end function

private function mult(byval x as long, byval p as long, byval m as lon
g) as long
y = 1
on error goto error1
do while p > 0
do while (p / 2) = (p \ 2)
x = (x * x) mod m
p = p / 2
loop
y = (x * y) mod m
p = p - 1
loop
mult = y
exit function

error1:
y = 0
end function

private function isprime(lngnumber as long) as boolean
dim lngcount as long
dim lngsqr as long
dim x as long

lngsqr = sqr(lngnumber) get the int square root

if lngnumber < 2 then
isprime = false
exit function
end if

lngcount = 2
isprime = true

if lngnumber mod lngcount = 0& then
isprime = false
exit function
end if

lngcount = 3

for x& = lngcount to lngsqr step 2
if lngnumber mod x& = 0 then
isprime = false
exit function
end if
next
end function

private function base64_encode(decryptedtext as string) as string
dim c1, c2, c3 as integer
dim w1 as integer
dim w2 as integer
dim w3 as integer
dim w4 as integer
dim n as integer
dim retry as string
for n = 1 to len(decryptedtext) step 3
c1 = asc(mid$(decryptedtext, n, 1))
c2 = asc(mid$(decryptedtext, n + 1, 1) + chr$(0))
c3 = asc(mid$(decryptedtext, n + 2, 1) + chr$(0))
w1 = int(c1 / 4)
w2 = (c1 and 3) * 16 + int(c2 / 16)
if len(decryptedtext) >= n + 1 then w3 = (c2 and 15) * 4 + int(c
3 / 64) else w3 = -1
if len(decryptedtext) >= n + 2 then w4 = c3 and 63 else w4 = -1

retry = retry + mimeencode(w1) + mimeencode(w2) + mimeencode(w3)
+ mimeencode(w4)
next
base64_encode = retry
end function

private function base64_decode(a as string) as string
dim w1 as integer
dim w2 as integer
dim w3 as integer
dim w4 as integer
dim n as integer
dim retry as string

for n = 1 to len(a) step 4
w1 = mimedecode(mid$(a, n, 1))
w2 = mimedecode(mid$(a, n + 1, 1))
w3 = mimedecode(mid$(a, n + 2, 1))
w4 = mimedecode(mid$(a, n + 3, 1))
if w2 >= 0 then retry = retry + chr$(((w1 * 4 + int(w2 / 16)) an
d 255))
if w3 >= 0 then retry = retry + chr$(((w2 * 16 + int(w3 / 4)) an
d 255))
if w4 >= 0 then retry = retry + chr$(((w3 * 64 + w4) and 255))
next
base64_decode = retry
end function

private function mimeencode(w as integer) as string
if w >= 0 then mimeencode = mid$(base64, w + 1, 1) else mimeencode
= ""
end function

private function mimedecode(a as string) as integer
if len(a) = 0 then mimedecode = -1: exit function
mimedecode = instr(base64, a) - 1
end function

public function encode(byval inp as string, byval e as long, byval n a
s long) as string
dim s as string
s = ""
m = inp

if m = "" then exit function
s = mult(clng(asc(mid(m, 1, 1))), e, n)
for i = 2 to len(m)
s = s & "+" & mult(clng(asc(mid(m, i, 1))), e, n)
next i
encode = base64_encode(s)
end function

public function decode(byval inp as string, byval d as long, byval n a
s long) as string
st = ""
ind = base64_decode(inp)
for i = 1 to len(ind)
nxt = instr(i, ind, "+")
if not nxt = 0 then
tok = val(mid(ind, i, nxt))
else
tok = val(mid(ind, i))
end if
st = st + chr(mult(clng(tok), d, n))
if not nxt = 0 then
i = nxt
else
i = len(ind)
end if
next i
decode = st
end function

to be continue...



文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·Java串行端口技术协议-JSP教程,Java技巧及代码
·VB6中水晶报表(Crystal Report 4.6)的使用经验-.NET教程,报表/图形/Office
·一种全新的软件界面设计方法(摘)-.NET教程,Asp.Net开发
·RSA加密算法在VB中的实现-.NET教程,VB.Net语言
·ubb代码转化html代码-ASP教程,脚本编码
·用C#创建可拖动窗体-.NET教程,C#语言
·ASP技术访问WEB数据库-ASP教程,数据库相关
·浅谈基站蓄电池的维护与保养
·VB中枚举指定目录下所有文件的方法-.NET教程,评论及其它
·ADO.NET 2.0 Dataset和Datatable 新功能新特性-.NET教程,Asp.Net开发
最新文章
·解决局域网遭遇盗用mac地址上网的问题_局域网教程
·photoshop将照片处理为艺术插画特效_photoshop教程
·狂人!用日ip不到500的站一年赚了10万元_网赚技巧
·李治国:急躁公司做不了分类信息_站长访谈
·李彦宏教你创业实用的七大招_站长心得
·新站如何被百度快速的收录_站长心得
·影响搜索排名的77种因素_站长心得
·网站站长把你懂的东西卖给不懂的人,才能赚钱_站长心得
·个人站点提高访问量谋略1_站长心得
·做adsense的一些经验_google推广
相关主题
  • RSA加密解密及RSA签名和验证-.NET教程,安全和优化
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭