用VB实现DES加解密算法(二)(2)

2008-02-23 06:48:14来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折



For i = 0 To 31
'P变换
CodeP(i) = RetS(P(i))

'产生L11,R11
R11(i) = L10(i) Xor CodeP(i)
L11(i) = R10(i)
Next


'进行第12次迭代
For i = 0 To 47
CodeE(i) = R11(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K12(i) '与K12按位作不进位加法运算
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))

'产生L12,R12
R12(i) = L11(i) Xor CodeP(i)
L12(i) = R11(i)
Next

'进行第13次迭代
For i = 0 To 47
CodeE(i) = R12(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K13(i) '与K13按位作不进位加法运算
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))

'产生L13,R13
R13(i) = L12(i) Xor CodeP(i)
L13(i) = R12(i)
Next


'进行第14次迭代
For i = 0 To 47
CodeE(i) = R13(E(i)) '经过E变换扩充,由32位变为48位
CodeE(i) = CodeE(i) Xor K14(i) '与K14按位作不进位加法运算
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
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:这个程序演示如何改变缺省的InputBox的外貌

下一篇:VB图像处理之像素的获取和输出