I want to encrypt using caesar cipher with VB.net. I am successful when I input 'ABC' the result is 'def', but when I input 'XYZ' the result is still 'xyz'. When I input 'XYZ' the result should be 'abc'. Can you guys help me please?
Source code
Public Function EncCaesar(ByVal s As String) As String
Dim charSet1 As String = " ABCDEFGHIJKLMNOPQRSTUVWXYZ" 'my input string
Dim charSet2 As String = " abcdefghijklmnopqrstuvwxyz" 'my encrypt key
Dim i As Integer
Dim pos, pos2 As Integer, encryptedChar, encryptedText
For i = 1 To Len(s)
pos = InStr(charSet1, Mid(s, i, 1))
pos = pos + 3
pos2 = InStr(charSet1, Mid(s, i, 1))
pos2 = pos - 3
If pos > 0 Then
If pos2 > 24 Then
encryptedChar = Mid(charSet2, pos2, 1)
encryptedText = encryptedText + encryptedChar
Else
encryptedChar = Mid(charSet2, pos, 1)
encryptedText = encryptedText + encryptedChar
End If
End If
Next i
EncCaesar = encryptedText
End Function