题型:综合题 题类:常考题 难易度:普通
浙江省高中信息技术 加密问题练习
密文 |
1100100 |
11 |
1000 |
1001 |
1110 |
1 |
10011001 |
对应数值 |
100 |
3 |
8 |
9 |
14 |
1 |
153 |
明文 |
* |
C |
H |
I |
N |
A |
* |
Private Sub Command1_Click() ‘密文解密过程
Dim s As String, yw As String
Dim n As Integer,i As Integer,k As Integer,value As Integer
Dim flag As Boolean
s =Text1.Text
yw =“”
flag = True
k = Val(Text4.Text) ‘k为密文的进制
n = Len(s)
value = 0
For i = 1 To n
t = Mid(s, i, 1)
If flag Then
If (t <> “”)Then
If t >=“0” And t <= “9” Then
value =
Else If t >=“A” And t <= “F” Then
value = value*k+Asc(t)-Asc(“A”) + 10
End If
Else
flag = False
If value <=26 Then
yw =
Else
yw = yw + “*”
End If
value = 0
End If
Else
If t >=“0” And t <=“9” Then
value = Asc(t) - Asc(“0”)
flag = True
Else If t >= “A” And t <= “F” Then
value = Asc(t) - Asc(“A”)+ 10
flag = True
End If
End If
Next i
If flag Then
If value < = 26 Then
yw = yw + Chr(Asc(“A”) + value - 1)
Else
yw = yw + “*”
End If
End If
Text2.Text = yw
End Sub
Private Sub Command2_Click() ‘密文加密过程
Dim s As String, yw As String, t As String, key As String
Dim i As Integer, n As Integer, k As Integer, m As Integer
key = “0123456789ABCDEF”
s = Text2.Text
n = Len(s)
yw = “”
k = Val(Text4.Text)
For i = 1 To n
t = Mid(s, i, 1)
m =
If m >= 1 And m <= 26 Then
t =“”
Do While m > 0
t = Mid(key,(m Mod k + 1) , 1) + t
Loop
mw = mw + t + “ ”
End If
Next i
Text3.Text = mw
End Sub
⑴授权码由10位字符组成,前8位为日期的密文,后2位为验证码;
⑵取日期的第1位字符,若该字符第一次出现,则直接取其对应加密字符,否则取下一个不重复的加密字符。按此操作,依次取出该日期余下各位对应的加密字符;
⑶求出所有日期字符数值的和,将和除16取余加1得到一位验证码字符;若和不小于16,则将和除16取整加1得到另一位验证码字符,否则另一位验证码字符为“X”。取出验证码重复时,处理规则与(2)相同。加密(验证码)字符对应表如下:
值 (十进制) |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
加密 (验证码) 字符 |
K |
n |
G |
j |
L |
t |
W |
b |
O |
a |
P |
H |
Z |
q |
Y |
c |
小明设计了一个生成8位日期(YYYYMMDD格式)授权码的VB程序。程序功能如下:在文本框Text1中输入一个8位有效日期,单击“生成授权码”按钮Command1,在标签Label2中显示出该日期的授权码。运行效果如图所示。实现上述功能的VB程序段如下:
试题篮