【发布时间】:2016-01-22 06:57:25
【问题描述】:
我正在创建一个具有加密和解密功能的程序。问题是它应该只适用于代码上的静态字符串。当输入的纯文本是最后一个时,它应该循环。例如,当我输入 0 且密钥为 2 时,字符串为“ABCDE...Z1234567890”,密文应为 B。我有四个文本框用于密钥、输入、明文和密文。这是我的代码。
Public Class Form1
Dim key As Integer
Const Intext As String = "abcdefghijklmnopqrstuvwxyz1234567890"
Private Sub btCipher_Click(sender As Object, e As EventArgs) Handles btCipher.Click
Dim plain, s, r As String
Dim i, j As Long
key = Val(txtKey.Text)
plain = txtInput.Text
For i = 1 To Len(plain)
r = Mid$(plain, i, 1)
j = (InStr(1, Intext, r))
If key > 36 Then
s = s & Mid$(Intext, j + (key - 36), 1)
Else
s = s & Mid$(Intext, j + key, 1)
End If
Next i
txtResult.Text = s
End Sub
Private Sub btDecipher_Click(sender As Object, e As EventArgs) Handles btDecipher.Click
Dim plain, s, r As String
Dim i, j As Long
key = Val(txtKey.Text)
plain = txtResult.Text
For i = 1 To Len(plain)
r = Mid$(plain, i, 1)
j = (InStr(1, Intext, r))
If key > 36 Then
s = s & Mid$(Intext, j + (key - 36), 1)
Else
s = s & Mid$(Intext, j - key, 1)
End If
Next i
txtText.Text = s
End Sub End Class
我的问题是它没有循环。也许有人可以帮忙。谢谢。
【问题讨论】:
-
key变量是Intext字符串中跳过的字符数吗?
标签: vb.net string loops encryption