Here's a quick rot13 encoder/decoder I wrote in VB. rot13 is good if you want to obfuscate some text, but security isn't a major concern. You can use it to perhaps "translate" some character's speech in a RPG into some strange alien tounge, or to help make private chat more private.
The convert function both encrypts and decrypts the text. There are perhaps more efficient ways of doing this, and if anyone is aware of it, please post the code.
Public Function Convert(stringIn As String) As String
Dim idx As Integer
Dim ret As String
Dim ch As String
Dim chB As Integer
Dim upper() As Variant
Dim upperROT13() As Variant
Dim lower() As Variant
Dim lowerROT13() As Variant
If Len(stringIn) > 0 Then
upper = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
upperROT13 = Array("N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M")
lower = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
lowerROT13 = Array("n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m")
For idx = 1 To Len(stringIn)
ch = Mid$(stringIn, idx, 1)
If ch >= "A" And ch <= "Z" Then
chB = Asc(ch) - 65
ch = upperROT13(chB)
ElseIf ch >= "a" And ch <= "z" Then
chB = Asc(ch) - 97
ch = lowerROT13(chB)
End If
ret = ret & ch
Next idx
End If
Convert = ret
End Function
Here's the same function ported to REALbasic:
Dim idx As Integer
Dim ret As String
Dim ch As String
Dim chB As Integer
Dim upper() As String
Dim upperROT13() As String
Dim lower() As String
Dim lowerROT13() As String
If Len(stringIn) > 0 Then
upper = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
upperROT13 = Array("N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M")
lower = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
lowerROT13 = Array("n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m")
For idx = 1 To Len(stringIn)
ch = Mid(stringIn, idx, 1)
If StrComp(ch, "A", 0) > -1 And StrComp(ch, "Z", 0) < 1 Then
chB = Asc(ch) - 65
ch = upperROT13(chB)
ElseIf StrComp(ch, "A", 0) > -1 And StrComp(ch, "z", 0) < 1 Then
chB = Asc(ch) - 97
ch = lowerROT13(chB)
End If
ret = ret + ch
Next idx
End If
Return ret