Since this is my first post, be sure to use lots of lube ok?
I have a "working" program for a Vigenère cipher, but I am having an issue that I can't pinpoint. Anytime an accent mark is used in the plain text i get a "Procedure call or argument is not valid" error. So trying to encrypt "Vigenère cipher" for example will not work.
Using the plaintext "f" with the keyword set as "b" the output is "È". Decryption handles these characters just fine. The following code is my encryption sub:
The decryption part is just the same except the for loop:Code:Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click Dim Key As String = txtKey.Text 'makes the password Dim TestString As String 'creates string variable to store encryptable material TestString = txtWord.Text If Len(Key) <= Len(TestString) Then 'this is run if the key is shorter than the encryptable material For i = 0 To (TestString.Length - Key.Length) 'concatenates each character of the key string to itself until its length equals TestString length Key = String.Concat(Key, Key.Substring(i, 1)) Next i End If 'this loop is where the substitution is done For i = 1 To TestString.Length 'convert string characters to character code equivalent and then the values are assigned to TestString Mid(TestString, i, 1) = Chr(Asc(Mid(TestString, i, 1)) + Asc(Key.Substring(i, 1))) Next i txtResult.Text = TestString End Sub
I hope there is just something small, but us new guys never have that much luck! Thanks in advance.Code:For i = 1 To TestString.Length Mid(TestString, i, 1) = Chr(Asc(Mid(TestString, i, 1)) - Asc(Key.Substring(i, 1))) Next i




Reply With Quote