题型:综合题 题类:常考题 难易度:困难
浙江省绍兴市诸暨中学2017-2018学年高二下学期信息技术期中考试试卷
例如:当明文M=HelloWorld,密钥K=abc时,密文C=HfnlpYosnd。运算过程如下所示:
明文:HelloWorld
密钥:abcabcabca
密文:HfnlpYosnd
依据上述算法描述设计了如下VB程序。请回答下列问题:
Const MIN_ASC = 65
Function X2D(x As String) As String
Dim s As String, zf As String, i As Integer
s = ""
For i = 1 To Len(x)
zf = Mid(x, i, 1)
If zf >= "a" And zf <= "z" Then
s=s+
Else
s = s + zf
End If
Next i
X2D = s
End Function
Private Sub Command1_Click()
Dim M As String, K As String, C As String, flag As Boolean
Dim i As Integer, t As Integer, ch As Integer, pos As Integer, j As Integer
M = Text1.Text '明文
K = Text2.Text '密钥
t = Len(K)
K = X2D(K)
C = ""
For i = 1 To Len(M)
ch = Asc(Mid(M, i, 1))
flag = False
If ch >= 97 And ch <= 122 Then ch = ch - 32: flag = True
pos= '密钥的字符位置值
If pos = 0 Then pos = t
j = Asc(Mid(K, pos, 1)) '密钥字符的ASCII值
ch = ch - MIN_ASC
j = j - MIN_ASC
ch=
ch = ch + MIN_ASC
If flag Then ch = ch + 32 '设置字母的大小写形式
C = C & Chr(ch)
Next i
Text3.Text = C
End Sub
位置 |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
数据 |
64 |
67 |
45 |
145 |
|
269 |
|
|
|
119 |
1275 |
试题篮