试题

试题 试卷

logo

题型:综合题 题类:常考题 难易度:普通

浙江省高中信息技术 加密问题练习

下面是一种加密解密的方法。当输入一串进制数字,用空格分离时,每个进制数字的数值与字母A…Z成一一对应关系。小明只要将这串数字的数值求出,然后将数字值转换成相应的字母即破解密码得到明文。若输入的进制数值超出1~26范围,则当成非法数值。表中数值100、153属于非法数值,用字符“*”表示,在解密过程中非法字符不予处理。

密文

1100100

11

1000

1001

1110

1

10011001

对应数值

100

3

8

9

14

1

153

明文

*

C

H

I

N

A

*

(1)、根据题意,若密文为16进制的“68 17 9 E 1F ”,则其明文为
(2)、实现上述功能的VB程序如下,请在划线处填上合适的代码。

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

举一反三
返回首页

试题篮