我有問題,我的代碼問題編程波雷費密碼
Public Class Form1
Dim lm(4, 4) As Char
Dim pt As String = ""
Dim ct As String = ""
Dim key As String = ""
Dim n1, n2, n3, n4, m1, m2, m3, m4 As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
key = k.Text
key.Replace(" ", "")
pt = plaintext.Text
If pt.Length Mod 2 <> 0 Then
pt = pt & "e"
End If
pt = UCase(pt)
pt.Replace("J", "I")
Dim Value As String
Dim NewValue As String
key.Replace("J", "I")
Value = key & "ABCDEFGHIKLMNOPQRSTUVWXYZ"
NewValue = ""
Value = UCase(Value)
NewValue = Value(0)
For i As Integer = 1 To Value.Length - 1
If Not (InStr(1, NewValue, Value(i)) > 0) Then
NewValue = NewValue & Value(i)
End If
Next
Dim p As Integer = 0
For n As Integer = 0 To 4
For m As Integer = 0 To 4
lm(n, m) = NewValue(p)
p = p + 1
Next
Next
Dim leave As Boolean = False
For q As Integer = 0 To pt.Length - 1 Step 2
For n1 = 0 To 4
For m1 = 0 To 4
If lm(n1, m1).Equals(pt(q)) Then
leave = True
Exit For
End If
Next
If leave Then
Exit For
End If
Next
leave = False
For n2 = 0 To 4
For m2 = 0 To 4
If lm(n2, m2).Equals(pt(q + 1)) Then
leave = True
Exit For
End If
Next
If leave Then
Exit For
End If
Next
If n1 = n2 Then
If m1 >= 4 Then
m3 = 0
Else
m3 = m1 + 1
End If
If m2 >= 4 Then
m4 = 0
Else
m4 = m2 + 1
End If
ElseIf m1 = m2 Then
If n1 >= 4 Then
n3 = 0
Else
n3 = n1 + 1
End If
If n2 >= 4 Then
n4 = 0
Else
n4 = n2 + 1
End If
Else
n3 = n1
m3 = m2
n4 = n2
m4 = m1
End If
ct = ct & lm(n3, m3) & lm(n4, m4)
Next
ciphertext.Text = ct
ct = ""
End Sub
End Class
它在這個線路CT給出錯誤= CT & LM(N3,M3)&流明(N4,M4)陣列超出範圍 我的cuoldn't找到爲什麼有人可以幫助我?
你可以使用調試器來檢查變量嗎?一個是超出範圍? – 2011-05-06 09:08:01
明文:莎拉 鍵:電腦 m4變爲5 – a2m22 2011-05-06 09:20:13