用vb实现DES加解密算法(三)(2)
2008-02-23 06:48:39来源:互联网 阅读 ()
For i = 0 To 31
'P变换
CodeP(i) = RetS(P(i))
'产生L7,R7
R7(i) = L6(i) Xor CodeP(i)
L7(i) = R6(i)
Next
'进行第8次迭代
For i = 0 To 47
CodeE(i) = R7(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K9(i) '与K9按位作不进位加法运算
Next
'分8组
For i = 0 To 5
CodeS1(i) = CodeE(i)
CodeS2(i) = CodeE(i 6)
CodeS3(i) = CodeE(i 12)
CodeS4(i) = CodeE(i 18)
CodeS5(i) = CodeE(i 24)
CodeS6(i) = CodeE(i 30)
CodeS7(i) = CodeE(i 36)
CodeS8(i) = CodeE(i 42)
Next
'S盒运算,得到8个数
S(0) = S1(CodeS1(5) CodeS1(0) * 2, CodeS1(4) CodeS1(3) * 2 CodeS1(2) * 4 CodeS1(1) * 8)
S(1) = S2(CodeS2(5) CodeS2(0) * 2, CodeS2(4) CodeS2(3) * 2 CodeS2(2) * 4 CodeS2(1) * 8)
S(2) = S3(CodeS3(5) CodeS3(0) * 2, CodeS3(4) CodeS3(3) * 2 CodeS3(2) * 4 CodeS3(1) * 8)
S(3) = S4(CodeS4(5) CodeS4(0) * 2, CodeS4(4) CodeS4(3) * 2 CodeS4(2) * 4 CodeS4(1) * 8)
S(4) = S5(CodeS5(5) CodeS5(0) * 2, CodeS5(4) CodeS5(3) * 2 CodeS5(2) * 4 CodeS5(1) * 8)
S(5) = S6(CodeS6(5) CodeS6(0) * 2, CodeS6(4) CodeS6(3) * 2 CodeS6(2) * 4 CodeS6(1) * 8)
S(6) = S7(CodeS7(5) CodeS7(0) * 2, CodeS7(4) CodeS7(3) * 2 CodeS7(2) * 4 CodeS7(1) * 8)
S(7) = S8(CodeS8(5) CodeS8(0) * 2, CodeS8(4) CodeS8(3) * 2 CodeS8(2) * 4 CodeS8(1) * 8)
'S盒运算32位结果
For i = 0 To 7
RetS(i * 4 0) = (S(i) And &H8) \ &H8
RetS(i * 4 1) = (S(i) And &H4) \ &H4
RetS(i * 4 2) = (S(i) And &H2) \ &H2
RetS(i * 4 3) = (S(i) And &H1) \ &H1
Next
For i = 0 To 31
'P变换
CodeP(i) = RetS(P(i))
'产生L8,R8
R8(i) = L7(i) Xor CodeP(i)
L8(i) = R7(i)
Next
'进行第9次迭代
For i = 0 To 47
CodeE(i) = R8(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K8(i) '与K8按位作不进位加法运算
Next
'分8组
For i = 0 To 5
CodeS1(i) = CodeE(i)
CodeS2(i) = CodeE(i 6)
CodeS3(i) = CodeE(i 12)
CodeS4(i) = CodeE(i 18)
CodeS5(i) = CodeE(i 24)
CodeS6(i) = CodeE(i 30)
CodeS7(i) = CodeE(i 36)
CodeS8(i) = CodeE(i 42)
Next
'S盒运算,得到8个数
S(0) = S1(CodeS1(5) CodeS1(0) * 2, CodeS1(4) CodeS1(3) * 2 CodeS1(2) * 4 CodeS1(1) * 8)
S(1) = S2(CodeS2(5) CodeS2(0) * 2, CodeS2(4) CodeS2(3) * 2 CodeS2(2) * 4 CodeS2(1) * 8)
S(2) = S3(CodeS3(5) CodeS3(0) * 2, CodeS3(4) CodeS3(3) * 2 CodeS3(2) * 4 CodeS3(1) * 8)
S(3) = S4(CodeS4(5) CodeS4(0) * 2, CodeS4(4) CodeS4(3) * 2 CodeS4(2) * 4 CodeS4(1) * 8)
S(4) = S5(CodeS5(5) CodeS5(0) * 2, CodeS5(4) CodeS5(3) * 2 CodeS5(2) * 4 CodeS5(1) * 8)
S(5) = S6(CodeS6(5) CodeS6(0) * 2, CodeS6(4) CodeS6(3) * 2 CodeS6(2) * 4 CodeS6(1) * 8)
S(6) = S7(CodeS7(5) CodeS7(0) * 2, CodeS7(4) CodeS7(3) * 2 CodeS7(2) * 4 CodeS7(1) * 8)
S(7) = S8(CodeS8(5) CodeS8(0) * 2, CodeS8(4) CodeS8(3) * 2 CodeS8(2) * 4 CodeS8(1) * 8)
'S盒运算32位结果
For i = 0 To 7
RetS(i * 4 0) = (S(i) And &H8) \ &H8
RetS(i * 4 1) = (S(i) And &H4) \ &H4
RetS(i * 4 2) = (S(i) And &H2) \ &H2
RetS(i * 4 3) = (S(i) And &H1) \ &H1
Next
For i = 0 To 31
'P变换
CodeP(i) = RetS(P(i))
'产生L9,R9
R9(i) = L8(i) Xor CodeP(i)
L9(i) = R8(i)
Next
'进行第10次迭代
For i = 0 To 47
CodeE(i) = R9(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K7(i) '与K7按位作不进位加法运算
Next
'分8组
For i = 0 To 5
CodeS1(i) = CodeE(i)
CodeS2(i) = CodeE(i 6)
CodeS3(i) = CodeE(i 12)
CodeS4(i) = CodeE(i 18)
CodeS5(i) = CodeE(i 24)
CodeS6(i) = CodeE(i 30)
CodeS7(i) = CodeE(i 36)
CodeS8(i) = CodeE(i 42)
Next
'S盒运算,得到8个数
S(0) = S1(CodeS1(5) CodeS1(0) * 2, CodeS1(4) CodeS1(3) * 2 CodeS1(2) * 4 CodeS1(1) * 8)
S(1) = S2(CodeS2(5) CodeS2(0) * 2, CodeS2(4) CodeS2(3) * 2 CodeS2(2) * 4 CodeS2(1) * 8)
S(2) = S3(CodeS3(5) CodeS3(0) * 2, CodeS3(4) CodeS3(3) * 2 CodeS3(2) * 4 CodeS3(1) * 8)
S(3) = S4(CodeS4(5) CodeS4(0) * 2, CodeS4(4) CodeS4(3) * 2 CodeS4(2) * 4 CodeS4(1) * 8)
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:建立拨号连接
下一篇:VB COM基础讲座之全面测试
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash