编写程序,实现对任意字符串的加密和解密操作
编写程序,实现对任意字符串的加密和解密操作。其中,对大小写英文字母的加密规则为:A→D,B→E,C→F,……,M→P,N→Q,……,W→Z,X→A,Y→B,Z→C;其他字...
编写程序,实现对任意字符串的加密和解密操作。其中,对大小写英文字母的加密规则为:A→D,B→E,C→F,……,M→P,N→Q,……,W→Z,X→A,Y→B,Z→C;其他字符保持原样不变。
要求程序界面如下所示。当在text1中输入需要加密的源文后,单击“加密”按钮,得到密文,并显示在text2中;当在text3中输入需要解密的密文后,单击“解密”按钮,得到源文,并显示在text4中,
要过程,原代码,要用VB编程,具体代码 展开
要求程序界面如下所示。当在text1中输入需要加密的源文后,单击“加密”按钮,得到密文,并显示在text2中;当在text3中输入需要解密的密文后,单击“解密”按钮,得到源文,并显示在text4中,
要过程,原代码,要用VB编程,具体代码 展开
1个回答
展开全部
Dim a() As String, b() As Integer, n As Integer
Text2 = ""
n = Len(Text1)
ReDim a(n)
ReDim b(n + 3)
For i = 1 To n
a(i) = Mid(Text1, i, 1)
If (Asc(a(i)) >= 65 And Asc(a(i)) <= 90) Or (Asc(a(i)) >= 97 And Asc(a(i)) <= 122) Then
b(i) = Asc(a(i)) + 3
If b(i) > Asc("Z") And b(i) < Asc("a") Then b(i) = Asc("A") + b(i) - Asc("Z") - 1
If b(i) > Asc("z") Then b(i) = Asc("a") + b(i) - Asc("z") - 1
Else
b(i) = Asc(a(i))
End If
a(i) = Chr(b(i))
Text2 = Text2 & a(i)
Next
Text3 = Text2
End Sub
Private Sub Command2_Click()
Dim a() As String, b() As Integer, n As Integer
Text4 = ""
n = Len(Text3)
ReDim a(n)
ReDim b(n + 3)
For i = 1 To n
a(i) = Mid(Text3, i, 1)
If (Asc(a(i)) >= 65 And Asc(a(i)) <= 90) Or (Asc(a(i)) >= 97 And Asc(a(i)) <= 122) Then
b(i) = Asc(a(i)) - 3
If b(i) >= 62 And b(i) < Asc("A") Then b(i) = Asc("Z") - (Asc("A") + b(i)) + 1
If b(i) >= 94 And b(i) < Asc("a") Then b(i) = Asc("z") - Asc("a") + b(i) + 1
Else
b(i) = Asc(a(i))
End If
a(i) = Chr(b(i))
Text4 = Text4 & a(i)
Next
End Sub
为便于调试对照,其中将加密后的文件直接放在了TEXT3中。调试完可去掉
Text2 = ""
n = Len(Text1)
ReDim a(n)
ReDim b(n + 3)
For i = 1 To n
a(i) = Mid(Text1, i, 1)
If (Asc(a(i)) >= 65 And Asc(a(i)) <= 90) Or (Asc(a(i)) >= 97 And Asc(a(i)) <= 122) Then
b(i) = Asc(a(i)) + 3
If b(i) > Asc("Z") And b(i) < Asc("a") Then b(i) = Asc("A") + b(i) - Asc("Z") - 1
If b(i) > Asc("z") Then b(i) = Asc("a") + b(i) - Asc("z") - 1
Else
b(i) = Asc(a(i))
End If
a(i) = Chr(b(i))
Text2 = Text2 & a(i)
Next
Text3 = Text2
End Sub
Private Sub Command2_Click()
Dim a() As String, b() As Integer, n As Integer
Text4 = ""
n = Len(Text3)
ReDim a(n)
ReDim b(n + 3)
For i = 1 To n
a(i) = Mid(Text3, i, 1)
If (Asc(a(i)) >= 65 And Asc(a(i)) <= 90) Or (Asc(a(i)) >= 97 And Asc(a(i)) <= 122) Then
b(i) = Asc(a(i)) - 3
If b(i) >= 62 And b(i) < Asc("A") Then b(i) = Asc("Z") - (Asc("A") + b(i)) + 1
If b(i) >= 94 And b(i) < Asc("a") Then b(i) = Asc("z") - Asc("a") + b(i) + 1
Else
b(i) = Asc(a(i))
End If
a(i) = Chr(b(i))
Text4 = Text4 & a(i)
Next
End Sub
为便于调试对照,其中将加密后的文件直接放在了TEXT3中。调试完可去掉
追问
好像是有错误啊,麻烦修改一下可以吗?
追答
对不起,第一行复制过来时漏掉了一句.在第一行补上下面的语句:
Private Sub Command1_Click()
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询