分享
 
 
 

用vb实现DES加解密算法(二)--加密

王朝vb·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

'sCode 待加密字串

'sKey 密钥字串(前8位有效)

Public Sub DES_Encode(ByRef sCode() As Byte, ByVal sKey As String, ByRef bReturn() As Byte)

Attribute DES_Encode.VB_Description = "加密 sCode:明文16进制串 sKey:密钥文本,前8位有效 bReturn:密文16进制串"

Dim tempKey() As Byte '存放密钥

Dim BinKey(63) As Byte '64位二进制原始密钥

Dim KeyPC_1(55) As Byte '存放56位密钥

Dim tempCode(7) As Byte '存放8位原始明文

Dim tempReturn(7) As Byte '存放8位密文

Dim BinCode(63) As Byte '存放64位明文

Dim CodeIP(63) As Byte '存放IP置换结果

Dim CodeE(47) As Byte 'E膨胀结果

Dim CodeP(31) As Byte 'P变换结果

Dim RetS(47) As Byte 'S盒运算32位结果

Dim S(7) As Byte 'S盒运算8个结果

Dim CodeS1(5) As Byte: Dim CodeS2(5) As Byte: Dim CodeS3(5) As Byte: Dim CodeS4(5) As Byte

Dim CodeS5(5) As Byte: Dim CodeS6(5) As Byte: Dim CodeS7(5) As Byte: Dim CodeS8(5) As Byte

Dim L0(31) As Byte: Dim R0(31) As Byte

Dim L1(31) As Byte: Dim R1(31) As Byte

Dim L2(31) As Byte: Dim R2(31) As Byte

Dim L3(31) As Byte: Dim R3(31) As Byte

Dim L4(31) As Byte: Dim R4(31) As Byte

Dim L5(31) As Byte: Dim R5(31) As Byte

Dim L6(31) As Byte: Dim R6(31) As Byte

Dim L7(31) As Byte: Dim R7(31) As Byte

Dim L8(31) As Byte: Dim R8(31) As Byte

Dim L9(31) As Byte: Dim R9(31) As Byte

Dim L10(31) As Byte: Dim R10(31) As Byte

Dim L11(31) As Byte: Dim R11(31) As Byte

Dim L12(31) As Byte: Dim R12(31) As Byte

Dim L13(31) As Byte: Dim R13(31) As Byte

Dim L14(31) As Byte: Dim R14(31) As Byte

Dim L15(31) As Byte: Dim R15(31) As Byte

Dim L16(31) As Byte: Dim R16(31) As Byte

Dim C0(27) As Byte: Dim D0(27) As Byte '16个密钥

Dim C1(27) As Byte: Dim D1(27) As Byte

Dim C2(27) As Byte: Dim D2(27) As Byte:

Dim C3(27) As Byte: Dim D3(27) As Byte:

Dim C4(27) As Byte: Dim D4(27) As Byte:

Dim C5(27) As Byte: Dim D5(27) As Byte:

Dim C6(27) As Byte: Dim D6(27) As Byte:

Dim C7(27) As Byte: Dim D7(27) As Byte:

Dim C8(27) As Byte: Dim D8(27) As Byte:

Dim C9(27) As Byte: Dim D9(27) As Byte:

Dim C10(27) As Byte: Dim D10(27) As Byte:

Dim C11(27) As Byte: Dim D11(27) As Byte:

Dim C12(27) As Byte: Dim D12(27) As Byte:

Dim C13(27) As Byte: Dim D13(27) As Byte:

Dim C14(27) As Byte: Dim D14(27) As Byte:

Dim C15(27) As Byte: Dim D15(27) As Byte:

Dim C16(27) As Byte: Dim D16(27) As Byte:

Dim C_D(55) As Byte 'Cn,Dn合并后的存放处

Dim K1(47) As Byte: Dim K2(47) As Byte: Dim K3(47) As Byte: Dim K4(47) As Byte:

Dim K5(47) As Byte: Dim K6(47) As Byte: Dim K7(47) As Byte: Dim K8(47) As Byte:

Dim K9(47) As Byte: Dim K10(47) As Byte: Dim K11(47) As Byte: Dim K12(47) As Byte:

Dim K13(47) As Byte: Dim K14(47) As Byte: Dim K15(47) As Byte: Dim K16(47) As Byte:

Dim i As Integer

Dim j As Integer

'取密钥的前8字节

tempKey = StrConv(sKey, vbFromUnicode)

ReDim Preserve tempKey(7)

For i = 0 To 7

BinKey(i * 8 + 0) = (tempKey(i) And &H80) \ &H80

BinKey(i * 8 + 1) = (tempKey(i) And &H40) \ &H40

BinKey(i * 8 + 2) = (tempKey(i) And &H20) \ &H20

BinKey(i * 8 + 3) = (tempKey(i) And &H10) \ &H10

BinKey(i * 8 + 4) = (tempKey(i) And &H8) \ &H8

BinKey(i * 8 + 5) = (tempKey(i) And &H4) \ &H4

BinKey(i * 8 + 6) = (tempKey(i) And &H2) \ &H2

BinKey(i * 8 + 7) = (tempKey(i) And &H1) \ &H1

Next

'PC_1转换

For i = 0 To 55

KeyPC_1(i) = BinKey(PC_1(i))

Next

'生成C0,D0

For i = 0 To 27

C0(i) = KeyPC_1(i)

D0(i) = KeyPC_1(i + 28)

Next

'***************************************************K1

'生成C1,D1

For i = 0 To 26

C1(i) = C0(i + Lsi(1))

D1(i) = D0(i + Lsi(1))

Next

C1(27) = C0(0)

D1(27) = D0(0)

'组合C1,D1成C_D

For i = 0 To 27

C_D(i) = C1(i)

C_D(i + 28) = D1(i)

Next

'PC_2转换,生成K1

For i = 0 To 47

K1(i) = C_D(PC_2(i))

Next

'***************************************************K2

'生成C2,D2

For i = 0 To 26

C2(i) = C1(i + Lsi(2))

D2(i) = D1(i + Lsi(2))

Next

C2(27) = C1(0)

D2(27) = D1(0)

'组合C2,D2成C_D

For i = 0 To 27

C_D(i) = C2(i)

C_D(i + 28) = D2(i)

Next

'PC_2转换,生成K2

For i = 0 To 47

K2(i) = C_D(PC_2(i))

Next

'***************************************************K3

'生成C3,D3

For i = 0 To 25

C3(i) = C2(i + Lsi(3))

D3(i) = D2(i + Lsi(3))

Next

C3(26) = C2(0)

D3(26) = D2(0)

C3(27) = C2(1)

D3(27) = D2(1)

'组合C3,D3成C_D

For i = 0 To 27

C_D(i) = C3(i)

C_D(i + 28) = D3(i)

Next

'PC_2转换,生成K3

For i = 0 To 47

K3(i) = C_D(PC_2(i))

Next

'***************************************************K4

'生成C4,D4

For i = 0 To 25

C4(i) = C3(i + Lsi(4))

D4(i) = D3(i + Lsi(4))

Next

C4(26) = C3(0)

D4(26) = D3(0)

C4(27) = C3(1)

D4(27) = D3(1)

'组合C4,D4成C_D

For i = 0 To 27

C_D(i) = C4(i)

C_D(i + 28) = D4(i)

Next

'PC_2转换,生成K4

For i = 0 To 47

K4(i) = C_D(PC_2(i))

Next

'***************************************************K5

'生成C5,D5

For i = 0 To 25

C5(i) = C4(i + Lsi(5))

D5(i) = D4(i + Lsi(5))

Next

C5(26) = C4(0)

D5(26) = D4(0)

C5(27) = C4(1)

D5(27) = D4(1)

'组合C5,D5成C_D

For i = 0 To 27

C_D(i) = C5(i)

C_D(i + 28) = D5(i)

Next

'PC_2转换,生成K5

For i = 0 To 47

K5(i) = C_D(PC_2(i))

Next

'***************************************************K6

'生成C6,D6

For i = 0 To 25

C6(i) = C5(i + Lsi(6))

D6(i) = D5(i + Lsi(6))

Next

C6(26) = C5(0)

D6(26) = D5(0)

C6(27) = C5(1)

D6(27) = D5(1)

'组合C6,D6成C_D

For i = 0 To 27

C_D(i) = C6(i)

C_D(i + 28) = D6(i)

Next

'PC_2转换,生成K6

For i = 0 To 47

K6(i) = C_D(PC_2(i))

Next

'***************************************************K7

'生成C7,D7

For i = 0 To 25

C7(i) = C6(i + Lsi(7))

D7(i) = D6(i + Lsi(7))

Next

C7(26) = C6(0)

D7(26) = D6(0)

C7(27) = C6(1)

D7(27) = D6(1)

'组合C7,D7成C_D

For i = 0 To 27

C_D(i) = C7(i)

C_D(i + 28) = D7(i)

Next

'PC_2转换,生成K7

For i = 0 To 47

K7(i) = C_D(PC_2(i))

Next

'***************************************************K8

'生成C8,D8

For i = 0 To 25

C8(i) = C7(i + Lsi(8))

D8(i) = D7(i + Lsi(8))

Next

C8(26) = C7(0)

D8(26) = D7(0)

C8(27) = C7(1)

D8(27) = D7(1)

'组合C8,D8成C_D

For i = 0 To 27

C_D(i) = C8(i)

C_D(i + 28) = D8(i)

Next

'PC_2转换,生成K8

For i = 0 To 47

K8(i) = C_D(PC_2(i))

Next

'***************************************************K9

'生成C9,D9

For i = 0 To 26

C9(i) = C8(i + Lsi(9))

D9(i) = D8(i + Lsi(9))

Next

C9(27) = C8(0)

D9(27) = D8(0)

'组合C9,D9成C_D

For i = 0 To 27

C_D(i) = C9(i)

C_D(i + 28) = D9(i)

Next

'PC_2转换,生成K9

For i = 0 To 47

K9(i) = C_D(PC_2(i))

Next

'***************************************************K10

'生成C10,D10

For i = 0 To 25

C10(i) = C9(i + Lsi(10))

D10(i) = D9(i + Lsi(10))

Next

C10(26) = C9(0)

D10(26) = D9(0)

C10(27) = C9(1)

D10(27) = D9(1)

'组合C10,D10成C_D

For i = 0 To 27

C_D(i) = C10(i)

C_D(i + 28) = D10(i)

Next

'PC_2转换,生成K10

For i = 0 To 47

K10(i) = C_D(PC_2(i))

Next

'***************************************************K11

'生成C11,D11

For i = 0 To 25

C11(i) = C10(i + Lsi(11))

D11(i) = D10(i + Lsi(11))

Next

C11(26) = C10(0)

D11(26) = D10(0)

C11(27) = C10(1)

D11(27) = D10(1)

'组合C11,D11成C_D

For i = 0 To 27

C_D(i) = C11(i)

C_D(i + 28) = D11(i)

Next

'PC_2转换,生成K11

For i = 0 To 47

K11(i) = C_D(PC_2(i))

Next

'***************************************************K12

'生成C12,D12

For i = 0 To 25

C12(i) = C11(i + Lsi(12))

D12(i) = D11(i + Lsi(12))

Next

C12(26) = C11(0)

D12(26) = D11(0)

C12(27) = C11(1)

D12(27) = D11(1)

'组合C12,D12成C_D

For i = 0 To 27

C_D(i) = C12(i)

C_D(i + 28) = D12(i)

Next

'PC_2转换,生成K12

For i = 0 To 47

K12(i) = C_D(PC_2(i))

Next

'***************************************************K13

'生成C13,D13

For i = 0 To 25

C13(i) = C12(i + Lsi(13))

D13(i) = D12(i + Lsi(13))

Next

C13(26) = C12(0)

D13(26) = D12(0)

C13(27) = C12(1)

D13(27) = D12(1)

'组合C13,D13成C_D

For i = 0 To 27

C_D(i) = C13(i)

C_D(i + 28) = D13(i)

Next

'PC_2转换,生成K13

For i = 0 To 47

K13(i) = C_D(PC_2(i))

Next

'***************************************************K14

'生成C14,D14

For i = 0 To 25

C14(i) = C13(i + Lsi(14))

D14(i) = D13(i + Lsi(14))

Next

C14(26) = C13(0)

D14(26) = D13(0)

C14(27) = C13(1)

D14(27) = D13(1)

'组合C14,D14成C_D

For i = 0 To 27

C_D(i) = C14(i)

C_D(i + 28) = D14(i)

Next

'PC_2转换,生成K14

For i = 0 To 47

K14(i) = C_D(PC_2(i))

Next

'***************************************************K15

'生成C15,D15

For i = 0 To 25

C15(i) = C14(i + Lsi(15))

D15(i) = D14(i + Lsi(15))

Next

C15(26) = C14(0)

D15(26) = D14(0)

C15(27) = C14(1)

D15(27) = D14(1)

'组合C15,D15成C_D

For i = 0 To 27

C_D(i) = C15(i)

C_D(i + 28) = D15(i)

Next

'PC_2转换,生成K15

For i = 0 To 47

K15(i) = C_D(PC_2(i))

Next

'***************************************************K16

'生成C16,D16

For i = 0 To 26

C16(i) = C15(i + Lsi(16))

D16(i) = D15(i + Lsi(16))

Next

C16(27) = C15(0)

D16(27) = D15(0)

'组合C16,D16成C_D

For i = 0 To 27

C_D(i) = C16(i)

C_D(i + 28) = D16(i)

Next

'PC_2转换,生成K16

For i = 0 To 47

K16(i) = C_D(PC_2(i))

Next

'**************************************************************************************

'将明文位数扩展为8的倍数

If (UBound(sCode) + 1) Mod 8 > 0 Then ReDim Preserve sCode(((UBound(sCode) + 1) \ 8 + 1) * 8 - 1)

'定义返回密文长度

ReDim bReturn(UBound(sCode))

For j = 0 To UBound(sCode) Step 8

'加密过程

'依次取8位加密

CopyMemory tempCode(0), sCode(j), 8

For i = 0 To 7

BinCode(i * 8 + 0) = (tempCode(i) And &H80) \ &H80

BinCode(i * 8 + 1) = (tempCode(i) And &H40) \ &H40

BinCode(i * 8 + 2) = (tempCode(i) And &H20) \ &H20

BinCode(i * 8 + 3) = (tempCode(i) And &H10) \ &H10

BinCode(i * 8 + 4) = (tempCode(i) And &H8) \ &H8

BinCode(i * 8 + 5) = (tempCode(i) And &H4) \ &H4

BinCode(i * 8 + 6) = (tempCode(i) And &H2) \ &H2

BinCode(i * 8 + 7) = (tempCode(i) And &H1) \ &H1

Next

'IP置换

For i = 0 To 63

CodeIP(i) = BinCode(IP(i))

Next

'分段

For i = 0 To 31

L0(i) = CodeIP(i)

R0(i) = CodeIP(i + 32)

Next

'进行第一次迭代

For i = 0 To 47

CodeE(i) = R0(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K1(i) '与K1按位作不进位加法运算

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))

'产生L1,R1

R1(i) = L0(i) Xor CodeP(i)

L1(i) = R0(i)

Next

'进行第二次迭代

For i = 0 To 47

CodeE(i) = R1(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K2(i) '与K2按位作不进位加法运算

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))

'产生L2,R2

R2(i) = L1(i) Xor CodeP(i)

L2(i) = R1(i)

Next

'进行第三次迭代

For i = 0 To 47

CodeE(i) = R2(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K3(i) '与K3按位作不进位加法运算

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))

'产生L3,R3

R3(i) = L2(i) Xor CodeP(i)

L3(i) = R2(i)

Next

'进行第四次迭代

For i = 0 To 47

CodeE(i) = R3(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K4(i) '与K4按位作不进位加法运算

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))

'产生L4,R4

R4(i) = L3(i) Xor CodeP(i)

L4(i) = R3(i)

Next

'进行第五次迭代

For i = 0 To 47

CodeE(i) = R4(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K5(i) '与K5按位作不进位加法运算

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))

'产生L5,R5

R5(i) = L4(i) Xor CodeP(i)

L5(i) = R4(i)

Next

'进行第六次迭代

For i = 0 To 47

CodeE(i) = R5(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K6(i) '与K6按位作不进位加法运算

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))

'产生L6,R6

R6(i) = L5(i) Xor CodeP(i)

L6(i) = R5(i)

Next

'进行第7次迭代

For i = 0 To 47

CodeE(i) = R6(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)

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))

'产生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 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))

'产生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 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))

'产生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 K10(i) '与K10按位作不进位加法运算

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))

'产生L10,R10

R10(i) = L9(i) Xor CodeP(i)

L10(i) = R9(i)

Next

'进行第11次迭代

For i = 0 To 47

CodeE(i) = R10(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K11(i) '与K11按位作不进位加法运算

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))

'产生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)

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))

'产生L14,R14

R14(i) = L13(i) Xor CodeP(i)

L14(i) = R13(i)

Next

'进行第15次迭代

For i = 0 To 47

CodeE(i) = R14(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K15(i) '与K15按位作不进位加法运算

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))

'产生L15,R15

R15(i) = L14(i) Xor CodeP(i)

L15(i) = R14(i)

Next

'进行第16次迭代

For i = 0 To 47

CodeE(i) = R15(E(i)) '经过E变换扩充,由32位变为48位

CodeE(i) = CodeE(i) Xor K16(i) '与K16按位作不进位加法运算

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))

'产生L11,R11

R16(i) = L15(i) Xor CodeP(i)

L16(i) = R15(i)

Next

For i = 0 To 31

BinCode(i) = L16(i)

BinCode(i + 32) = R16(i)

Next

For i = 0 To 63

CodeIP(i) = BinCode(IP_1(i))

Next

For i = 0 To 7

tempReturn(i) = CodeIP(i * 8 + 0) * &H80

tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 1) * &H40

tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 2) * &H20

tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 3) * &H10

tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 4) * &H8

tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 5) * &H4

tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 6) * &H2

tempReturn(i) = tempReturn(i) + CodeIP(i * 8 + 7) * &H1

Next

CopyMemory bReturn(j), tempReturn(0), 8

Next

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有