I'm trying to make a basic caesar cipher in Visual Basic 2010 Express (Console Application) but whenever it encrypts the string it correctly encrypts the first character and replaces all the others with that same encrypted character.
I have tried everything I could think of and have searched all across the internet and can't find a basic console application way that works, I know it can be done as it was set as a homework assignment and there are other people in the class who have got through this issue.
Sub Main()
Dim Message As String
Dim EncMessage As String = ""
Dim counter As Integer = 0
Do Until counter = 1 'This just repeats the program
Console.Write("Please enter a string to encrypt: ")
Message = Console.ReadLine
Dim LetterArray() As Char = Message.ToCharArray
For i = 0 To LetterArray.Length - 1
EncMessage = EncMessage & Chr(Asc(LetterArray) + 3) 'Encrypts the characters one by one (i think this is where the issue is as it encrypts the first one correct but then just outputs the same character on top the correct amount of times)
'This if statement just loops the characters X Y Z x y z back to the start of the alphabet as it is only meant to encrypt letters
If EncMessage = "{" Then
EncMessage = Chr(Asc(LetterArray) - 23)
ElseIf EncMessage = "|" Then
EncMessage = Chr(Asc(LetterArray) - 23)
ElseIf EncMessage = "}" Then
EncMessage = Chr(Asc(LetterArray) - 23)
ElseIf EncMessage = "[" Then
EncMessage = Chr(Asc(LetterArray) - 23)
ElseIf EncMessage = "\" Then
EncMessage = Chr(Asc(LetterArray) - 23)
ElseIf EncMessage = "]" Then
EncMessage = Chr(Asc(LetterArray) - 23)
End If
Next
Console.WriteLine(EncMessage)
Console.ReadKey()
EncMessage = ""
Loop
End Sub
For example, if I enter "sausage" it will output "vvvvvvv" but it should output "vdtvdjh" because I want it to shift forward 3 characters. Please help, thank you.