编写解密的VB程序,功能如下:在文本框Text1中输入密文,单击“解密”按钮Command1,在文本框Text2中显示去重后的文本,并在标签Label1中显示明文。程序运行界面如图所示。

Private Sub Command1Click( )
Dim s1 As String, s2 As String, c As String, mw As String
Dim i As Integer
s1= Text1.Text
s2 = Mid(s1, 1, 1)
For i=2 To
c=Mid(s1, i, 1)
If c>="A" And c<= "Z" Then
IfThen s2 =s2 +c
Else
s2 =s2+c
End If
Next i
mw=“”
i=6
Do While i<= Len(s2)
mw = mw + Mid(s2, i, 1)
Loop
Text2. Text= s2
Label1. Caption =mw
End Sub
def decrypt(code,key):#code:密文key: 密钥
code_ new = "
for s in code:
m= ① #按照输入的key值,做移位运算
if m<97:
②
code_ new + = chr(m)
returm code_ new
code = input(‘请输入密文:’)
key = intinput(‘请输入密钥:’)
code_ new = decrypt(code, key)
print(code_ new)
① ②
步骤一、输入大写字母A-F的字符串,通过随机生成的keys列表进行匹配,找到相应的key,进行第1轮加密,得到相应的数字列表a。
步骤二、根据上述结果对加密后列表中的元素按偏移量K(K为正整数)发生偏移,每个元素从右往左向前移动K位,将偏移后结果存储在列表b中。
例如:
整体运行结果如下图所示:
import random
#随机生成 keys 列表
n=6
i=0
keys=[ ]
while i<n:
key=random.randint(1,9)
if key not in keys:
keys.append(key)
print("随机生成加密列表 keys:",keys)
#第1重加密:将输入的字母经过keys列表加密转换为a列表
a=[ ]
s=input("输入您要加密的字母(A-F):")
for i in s:
a.append(keys[])
print("经过第1轮keys列表加密后:",a)
#第2重加密:偏移加密
k=int(input("请输入偏移量K:"))
b=[0]*len(a)
for i in range(len(a)):
b[i]=a[]
print("经过第2轮加密后:",b)