高中信息技术VB问题。
某信息加密程序,对输入的明文(由英文字母或数字组成的字符串)进行加密,输出加密后得到的密文。数据加密方法为对明文中的每个字符进行如下处理:1)将该字符的ASCII码转换成...
某信息加密程序,对输入的明文(由英文字母或数字组成的字符串)进行加密,输出加密后得到的密文。数据加密方法为对明文中的每个字符进行如下处理:1)将该字符的ASCII码转换成对应的8位二进制;2)将对应的8位二进制数进行按位取反(1变0,0变1);3)将产生的8位二进制数循环左移三次;4)最后产生的8位二进制数转换成对应的十六进制数例如,明文大写字母“A”通过上述加密算法加密后生成的密文是“F5”,信息加密过程如图小李编写了加密算法的VB程序,在文本框Text1中输入明文,单击“生成密文”按钮Command1,程序对明文数据依次进行加密处理,加密后生成的密文显示在文本框Text2中。程序运行界面如图(1)如果输入明文为大写字母“F”,则生成的密文是(CD)(2)实现上述功能的VB程序如下,请在大括号处填入合适代码。Function btoh(m As String) As String 将4位2进制数转化成对应的十六进制数 Dim s As Integer, i As Integer Dim str As String str="0123456789ABCDEF" s=0 For i=1 to 4 s=s*2+Val(Mid(m,i,1)) next i ----- btoh=mid(str,s+1,1)-----end FunctionPrivate Sub Commandl_Click() Dim ans As String,s As String,ch As String,ret As String Dim i As Integer,ascl As Integer,n As Integer s=text1.text ans="" For i=1 to len(s) ch=Mid(s,i,1) 提取第i个字符存入变量ch ascl=Asc(ch) ret=“” For m=1 to 8 完成加密步骤1)和步骤2) n=(ascl+1)mod2 ret=n&ret ----- ascl=ascl\2 ----- next m ret=Mid(ret,4,5)+Mid(ret,1,3) 完成加密步骤3)和步骤4 s1=btoh(Mid(ret,1,4)) s2=btoh(Mid(ret,5,4)) ans=ans&s1&s2 将第i个加密后的字符添加到变量ans的末尾 Next i Text2.Text=ansend Sub题目是这样 能不能把程序的每一行步骤用文字解释下啊----------里面的内容是题目要填的地方,填的对不对啊。
Function btoh(m As String) As String
Dim s As Integer, i As Integer
Dim str As String str="0123456789ABCDEF"
s=0
For i=1 to 4
s=s*2+Val(Mid(m,i,1))
next i
----- btoh=mid(str,s+1,1)-----
end Function
Private Sub Commandl_Click()
Dim ans As String,s As String,ch As String,ret As String
Dim i As Integer,ascl As Integer,n As Integer
s=text1.text
ans=""
For i=1 to len(s)
ch=Mid(s,i,1)
ascl=Asc(ch)
ret=“”
For m=1 to 8
n=(ascl+1)mod2
ret=n&ret
----- ascl=ascl\2 -----
next m
ret=Mid(ret,4,5)+Mid(ret,1,3)
s1=btoh(Mid(ret,1,4))
s2=btoh(Mid(ret,5,4))
ans=ans&s1&s2
Next i
Text2.Text=ans
end Sub 展开
Function btoh(m As String) As String
Dim s As Integer, i As Integer
Dim str As String str="0123456789ABCDEF"
s=0
For i=1 to 4
s=s*2+Val(Mid(m,i,1))
next i
----- btoh=mid(str,s+1,1)-----
end Function
Private Sub Commandl_Click()
Dim ans As String,s As String,ch As String,ret As String
Dim i As Integer,ascl As Integer,n As Integer
s=text1.text
ans=""
For i=1 to len(s)
ch=Mid(s,i,1)
ascl=Asc(ch)
ret=“”
For m=1 to 8
n=(ascl+1)mod2
ret=n&ret
----- ascl=ascl\2 -----
next m
ret=Mid(ret,4,5)+Mid(ret,1,3)
s1=btoh(Mid(ret,1,4))
s2=btoh(Mid(ret,5,4))
ans=ans&s1&s2
Next i
Text2.Text=ans
end Sub 展开
3个回答
展开全部
Function btoh(m As String) As String '实现4位二进制转1位十六进制
Dim s As Integer, i As Integer
Dim str As String
str = "0123456789ABCDEF" '十六进制串,F表示10进制15
s = 0
For i = 1 To 4
s = s * 2 + Val(Mid(m, i, 1)) '4位二进制转10进制
Next i
btoh = Mid(str, s + 1, 1) '-----从十六进制串中取一个对应数
End Function
Private Sub Command1_Click()
Dim ans As String, s As String, ch As String, ret As String
Dim i As Integer, ascl As Integer, n As Integer
s = Text1.Text
ans = ""
For i = 1 To Len(s)
ch = Mid(s, i, 1) '从字符串中取一个字符
ascl = Asc(ch) '把字符转换成它的ascii码
ret = ""
For m = 1 To 8
n = (ascl + 1) Mod 2 'asc1+1与2取余保证按位取反
ret = n & ret '生成取反后的二进制串,如果asc1不加1,可得原码
ascl = ascl \ 2 '-----辗转相除求余法,可以去看10进制如何转成二进制
Next m
ret = Mid(ret, 4, 5) + Mid(ret, 1, 3) '循环左移三位
s1 = btoh(Mid(ret, 1, 4)) '二进制数前4位转16进制
s2 = btoh(Mid(ret, 5, 4)) '二进制数后4位转16进制
ans = ans & s1 & s2
Next i
Text2.Text = ans
End Sub
对于一个高中生来说,这题有点难为人,它涉及的进制换算过多,要看懂它并不容易。
展开全部
Private Sub Command1_Click() Dim fs As Single fs = Val(InputBox("请输入成绩", "入成绩", 60)) Select Case fs Case Is < 60 MsgBox "不及格" Case 60 To 85 MsgBox "及格" Case Is > 85 MsgBox "优秀" End Select End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只需执行现在现场吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询