'encrypt = true (encrypt), encrypt = false (Decrypt)
Sub Rot13(input As String, encrypt As Boolean) As String
Dim output As StringBuilder
output.Initialize
Dim alphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Dim rot13Alphabet As String = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
Dim sourceAlphabet As String
Dim targetAlphabet As String
If encrypt Then
sourceAlphabet = alphabet
targetAlphabet = rot13Alphabet
Else
sourceAlphabet = rot13Alphabet
targetAlphabet = alphabet
End If
For i = 0 To input.Length - 1
Dim c As Char = input.CharAt(i)
Dim index As Int = sourceAlphabet.IndexOf(c)
If index <> -1 Then
output.Append(targetAlphabet.CharAt(index))
Else
output.Append(c)
End If
Next
Return output.ToString
End Sub