<%
Class Cls_DES
Private IPRule, CPRule, EPRule, PRule, SBox(7), PCRule(1), MvRule
Private K(16), L(16), R(16)
Private FillCode, DesStatus
Private Sub Class_Initialize()
DesStatus = -1
FillCode = "0001101"
IPRule = "58,50,42,34,26,18,10,2," &_
"60,52,44,36,28,20,12,4," &_
"62,54,46,38,30,22,14,6," &_
"64,56,48,40,32,24,16,8," &_
"57,49,41,33,25,17, 9,1," &_
"59,51,43,35,27,19,11,3," &_
"61,53,45,37,29,21,13,5," &_
"63,55,47,39,31,23,15,7,"
CPRule = "40, 8,48,16,56,24,64,32," &_
"39, 7,47,15,55,23,63,31," &_
"38, 6,46,14,54,22,62,30," &_
"37, 5,45,13,53,21,61,29," &_
"36, 4,44,12,52,20,60,28," &_
"35, 3,43,11,51,19,59,27," &_
"34, 2,42,10,50,18,58,26," &_
"33, 1,41, 9,49,17,57,25,"
EPRule = "32, 1, 2, 3, 4, 5," &_
" 4, 5, 6, 7, 8, 9," &_
" 8, 9,10,11,12,13," &_
"12,13,14,15,16,17," &_
"16,17,18,19,20,21," &_
"20,21,22,23,24,25," &_
"24,25,26,27,28,29," &_
"28,29,30,31,32, 1,"
PRule = "16, 7,20,21,29,12,28,17," &_
" 1,15,23,26, 5,18,31,10," &_
" 2, 8,24,14,32,27, 3, 9," &_
"19,13,30, 6,22,11, 4,25,"
SBox(0) = "14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7," &_
" 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8," &_
" 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0," &_
"15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13,"
SBox(1) = "15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10," &_
" 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5," &_
" 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15," &_
"13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9,"
SBox(2) = "10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8," &_
"13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1," &_
"13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7," &_
" 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12,"
SBox(3) = " 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15," &_
"13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9," &_
"10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4," &_
" 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14,"
SBox(4) = " 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9," &_
"14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6," &_
" 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14," &_
"11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3,"
SBox(5) = "12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11," &_
"10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8," &_
" 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6," &_
" 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13,"
SBox(6) = " 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1," &_
"13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6," &_
" 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2," &_
" 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12,"
SBox(7) = "13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7," &_
" 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2," &_
" 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8," &_
" 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11,"
PCRule(0) = "57,49,41,33,25,17, 9," &_
" 1,58,50,42,34,26,18," &_
"10, 2,59,51,43,35,27," &_
"19,11, 3,60,52,44,36," &_
"63,55,47,39,31,23,15," &_
" 7,62,54,46,38,30,22," &_
"14, 6,61,53,45,37,29," &_
"21,13, 5,28,20,12, 4,"
PCRule(1) = "14,17,11,24, 1, 5, 3,28," &_
"15, 6,21,10,23,19,12, 4," &_
"26, 8,16, 7,27,20,13, 2," &_
"41,52,31,37,47,55,30,40," &_
"51,45,33,48,44,49,39,56," &_
"34,53,46,42,50,36,29,32,"
MvRule = "1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1"
End Sub
Private Function Permute(ByVal Rule, ByVal Text)
Dim P_Rule, Num, PText
PText = ""
P_Rule = Split(Rule, ",")
For Each Num In P_Rule
Num = Trim(Num) & ""
If Num <> "" Then
Num = CLng(Num)
PText = PText & Mid(Text, Num, 1)
End If
Next
Erase P_Rule
Permute = PText
End Function
Private Function CreateKey()
Dim IPKey, C(16), D(16), i, Mv_Rule, MvLen
IPKey = Permute(PCRule(0), K(0))
C(0) = Left(IPKey, 28)
D(0) = Right(IPKey, 28)
Mv_Rule = Split(MvRule, ",")
For i = 1 To 16
MvLen = CLng(Trim(Mv_Rule(i - 1)))
C(i) = Right(C(i -1), Len(C(i -1)) - MvLen) & Left(C(i -1), MvLen)
D(i) = Right(D(i -1), Len(D(i -1)) - MvLen) & Left(D(i -1), MvLen)
K(i) = Permute(PCRule(1), C(i) & D(i))
Next
End Function
Private Function IP(ByVal Text)
Dim IPText
IPText = Permute(IPRule, Text)
L(0) = Left(IPText, 32)
R(0) = Right(IPText, 32)
IP = IPText
End Function
Private Function IterativeLR()
Dim i
For i = 1 To 16
L(i) = R(i - 1)
R(i) = B_XOR(L(i - 1), F(R(i - 1), K(i)))
Next
End Function
Private Function F(ByVal RText, ByVal Keys)
Dim EPText, XORText, Result, SKey(7), i, x, y
Result = ""
EPText = Permute(EPRule, RText)
XORText = B_XOR(EPText, Keys)
For i = 1 To Len(XORText) \ 6
SKey(i - 1) = Mid(XORText, (i - 1) * 6 + 1, 6)
x = BinaryToDecimal(Left(SKey(i - 1), 1) & Right(SKey(i - 1), 1))
y = BinaryToDecimal(Mid(SKey(i - 1), 2, 4))
SKey(i - 1) = DecimalToBinary(Trim(Split(SBox(i -1), ",")(x * 16 + y)))
If Len(SKey(i - 1)) < 4 Then
Select Case (4 - Len(SKey(i - 1)))
Case 1
SKey(i - 1) = "0" & SKey(i - 1)
Case 2
SKey(i - 1) = "00" & SKey(i - 1)
Case 3
SKey(i - 1) = "000" & SKey(i - 1)
End Select
End If
Result = Result & SKey(i - 1)
Next
Result = Permute(PRule, Result)
F = Result
End Function
Private Function B_XOR(ByVal Expression1, ByVal Expression2)
Dim E, K, i, XORText
XORText = ""
E = Trim(Expression1) & ""
K = Trim(Expression2) & ""
For i = 1 To Len(K)
XORText = XORText & CStr(CInt(Mid(E, i, 1)) Xor CInt(Mid(K, i, 1)))
Next
B_XOR = XORText
End Function
Private Function BinaryToDecimal(ByVal binNum)
Dim Binary, Decimal, i, Length
Decimal = 0
Binary = Trim(binNum) & ""
If Binary <> "" Then
While Left(Binary, 1) = "0"
Binary = Right(Binary, Len(Binary) - 1)
Wend
Length = Len(Binary)
For i = 1 To Length
Decimal = Decimal + CInt(Mid(Binary, i, 1)) * 2^(Length - i)
Next
End If
BinaryToDecimal = Decimal
End Function
Private Function DecimalToBinary(ByVal decNum)
Dim Decimal, Binary, division
Binary = ""
Decimal = Trim(decNum) & ""
If Decimal <> "" Then
Decimal = CLng(Decimal)
While Decimal > 1
Binary = Binary & CStr(Decimal Mod 2)
Decimal = Decimal \ 2
Wend
Binary = StrReverse(Binary & Decimal)
E

普通网友
- 粉丝: 33
最新资源
- MATLAB深度学习工具包CAM可解释性分析的实时编辑器教程_Live Editor tutorials for MAT
- 相信很多 iOS 程序猿都有进入 BAT、字节跳动、美团、京东、360和小米等大厂的梦想,进入唯一途径就是通过面试,面试
- 数据可视化-Echarts 小程序数据可视化展示.zip
- Matlab反演集合,包括迭代方法和全局优化方法。_Matlab Inversion Collection, inclu
- 用于提示用户首次进入小程序时,点击右上角菜单进行【添加到我的小程序】操作.zip
- 微信小程序canvas签字板.zip
- 野火IM微信小程序版.zip
- 追格企业官网小程序Free(又称酱茄企业官网free),专为中小企业开发的轻量级企业建站小程序(基于uni-app +
- 上应大众点评小程序.zip
- SteamCN Forum WeChat Mini Program. SteamCN 蒸汽动力论坛微信小程序.zip
- 轻量级微信小程序SDK,支持.NET Framework以及.NET Core。目前已提供Abp模块的封装,支持开箱即用
- 在MATLAB中实现反向传播算法,以检测NDN(命名数据网络)中的DDOS(分布式拒绝服务)攻击。_Implementa
- 【嘟嘟早教卡】小程序源码,由 Taro 及 Tailwind CSS 构建而成。.zip
- mpvue和云开发写的一款小程序,踩坑记录.zip
- vue+django+uniapp实现仓储物流管理系统(网页端+小程序).zip
- 本文的Matlab代码_模糊判别图像表示_分数阶雅可比傅里叶矩__Matlab code for the paper _
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


