Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 rot13
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

IAC249
Squire

USA
39 Posts

Posted - May 01 2006 :  11:45:58 AM  Show Profile  Visit IAC249's Homepage  Send IAC249 a Yahoo! Message  Reply with Quote
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  
  

Edited by - IAC249 on May 01 2006 11:49:39 AM
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.23 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.