udfStrROT13
str udfStrROT13V1 (str)
str udfStrROT13V2 (str)
str udfStrROT13V3 (str)
str udfStrROT13V4 (str)
str udfStrROT13V5 (str)
str udfStrROT13V6 (str)
str udfStrROT13V7 (str)
str udfStrROT13V8 (str)
str udfStrROT13V9 (str)
str udfStrROT13V10 (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V6 (strString)
arrU = ArrayFromStr ("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM")
arrL = ArrayFromStr ("abcdefghijklmnopqrstuvwxyzabcdefghijklm")
arrS = ArrayFromStr (strString)
intLast = ArrInfo (arrS, 1) - 1
For intS = 0 To intLast
   intN = Char2Num (arrS [intS])
   If intN < 65 Then Continue
   If intN > 122 Then Continue
   If intN < 91 Then arrS [intS] = arrU[IntN - 52]
      Else If intN > 96 Then arrS [intS] = arrL[IntN - 84]
Next
Return ArrayToStr (arrS)
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
;
; (c)Detlev Dalitz.20100202.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------



; Following listed UDF's demonstrate alternative algorithms, but not so effective like udfStrROT13V6.

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V1 (strString)
strLC = "abcdefghijklmnopqrstuvwxyzabcdefghijklm"
strUC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM"
intLen = StrLen (strString)
strROT13 = ""
For intI = 1 To intLen
   strChar = StrSub (strString, intI, 1)
   intPos = StrScan (strLC, strChar, 1, @FWDSCAN)
   If intPos
      strROT13 = StrCat (strROT13, StrSub (strLC, intPos + 13, 1))
   Else
      intPos = StrScan (strUC, strChar, 1, @FWDSCAN)
      If intPos
         strROT13 = StrCat (strROT13, StrSub (strUC, intPos + 13, 1))
      Else
         strROT13 = StrCat (strROT13, strChar)
      EndIf
   EndIf
Next
Return strROT13
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
; Algorithm adapted from "http://www.ericphelps.com/scripting/"
; Modified by Detlev Dalitz.20020625.20020808
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V2 (strString)
strLC = "abcdefghijklmnopqrstuvwxyz"
strUC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
intLen = StrLen (strString)
strROT13 = ""
For intI = 1 To intLen
   strChar = StrSub (strString, intI, 1)
   intPos = StrScan (strLC, strChar, 1, @FWDSCAN)
   If intPos
      intPos = intPos + 13
      If (intPos > 26) Then intPos = intPos - 26
      strROT13 = StrCat (strROT13, StrSub (strLC, intPos, 1))
   Else
      intPos = StrScan (strUC, strChar, 1, @FWDSCAN)
      If intPos
         intPos = intPos + 13
         If (intPos > 26) Then intPos = intPos - 26
         strROT13 = StrCat (strROT13, StrSub (strUC, intPos, 1))
      Else
         strROT13 = StrCat (strROT13, strChar)
      EndIf
   EndIf
Next
Return strROT13
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
; Algorithm adapted from "http://www.ericphelps.com/scripting/"
; Modified by Detlev Dalitz.20020625.20020808.20030207
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V3 (strString)
strLC = "abcdefghijklmnopqrstuvwxyz"
strUC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
strROTLC = "nopqrstuvwxyzabcdefghijklm"
strROTUC = "NOPQRSTUVWXYZABCDEFGHIJKLM"
intLen = StrLen (strString)
strROT13 = ""
For intI = 1 To intLen
   strChar = StrSub (strString, intI, 1)
   intPos = StrScan (strLC, strChar, 1, @FWDSCAN)
   If intPos
      strROT13 = StrCat (strROT13, StrSub (strROTLC, intPos, 1))
   Else
      intPos = StrScan (strUC, strChar, 1, @FWDSCAN)
      If intPos
         strROT13 = StrCat (strROT13, StrSub (strROTUC, intPos, 1))
      Else
         strROT13 = StrCat (strROT13, strChar)
      EndIf
   EndIf
Next
Return strROT13
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
; Algorithm adapted from "http://www.ericphelps.com/scripting/"
; Modified by Detlev Dalitz.20020625.20020808.20030207
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V4 (strString)
strROT13 = ""
intLen = StrLen (strString)
For intI = 1 To intLen
   strChar = StrSub (strString, intI, 1)
   intN = Char2Num (strChar)
   intB = 64 ^ intN & 223
   If intB && intB < 27 Then strROT13 = StrCat (strROT13, Num2Char ((intN & 96 | (intB + 12) mod 26) + 1))
      Else strROT13 = StrCat (strROT13, strChar)
Next
Return strROT13
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
; Algorithm adapted from C source, origin of <fine@cis.ohio-state.edu> Thomas A. Fine, Ohio State University,
; Department of Computer and Information Science, 2036 Neil Avenue Mall, Columbus, Ohio  43210, USA.
;
; Detlev Dalitz.20031021.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V5 (strString)
arrU = ArrayFromStr ("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM")
arrL = ArrayFromStr ("abcdefghijklmnopqrstuvwxyzabcdefghijklm")
arrS = ArrayFromStr (strString)
intLast = ArrInfo (arrS, 1) - 1
For intS = 0 To intLast
   If StrLower (arrS [intS]) == arrS [intS]
      intN = Char2Num (arrS [intS])
      If intN < 97 Then Continue
      If intN > 122 Then Continue
      arrS [intS] = arrL[intN - 84]
   Else
      intN = Char2Num (arrS [intS])
      If intN < 65 Then Continue
      If intN > 90 Then Continue
      arrS [intS] = arrU[intN - 52]
   EndIf
Next
Return ArrayToStr (arrS)
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
;
; Detlev Dalitz.20100202.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V7 (strString)
intLen = StrLen (strString)
strOut = ""
For intS = 1 To intLen
   strChar = StrSub (strString, intS, 1)
   If strChar >= "A" && strChar <= "M" || strChar >= "a" && strChar <= "m"
      strChar = Num2Char (Char2Num (strChar) + 13)
      ElseIf strChar >= "N" && strChar <= "Z" || strChar >= "n" && strChar <= "z"
      strChar = Num2Char (Char2Num (strChar) - 13)
   EndIf
   strOut = strOut : strChar
Next
Return strOut
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
;
; (c)Detlev Dalitz.20100216.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V8 (strString)
arrS = ArrayFromStr (strString)
intLast = ArrInfo (arrS, 1) - 1
For intS = 0 To intLast
   If arrS [intS] >= "A" && arrS [intS] <= "M" || arrS [intS] >= "a" && arrS [intS] <= "m"
      arrS [intS] = Num2Char (Char2Num (arrS [intS]) + 13)
      ElseIf arrS [intS] >= "N" && arrS [intS] <= "Z" || arrS [intS] >= "n" && arrS [intS] <= "z"
      arrS [intS] = Num2Char (Char2Num (arrS [intS]) - 13)
   EndIf
Next
Return ArrayToStr (arrS)
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
;
; (c)Detlev Dalitz.20100216.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V9 (strString)
arrS = ArrayFromStr (strString)
intLast = ArrInfo (arrS, 1) - 1
For intS = 0 To intLast
   strChar = arrS [intS]
   If strChar >= "A" && strChar <= "M" || strChar >= "a" && strChar <= "m"
      arrS [intS] = Num2Char (Char2Num (strChar) + 13)
      ElseIf strChar >= "N" && strChar <= "Z" || strChar >= "n" && strChar <= "z"
      arrS [intS] = Num2Char (Char2Num (strChar) - 13)
   EndIf
Next
Return ArrayToStr (arrS)
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
;
; (c)Detlev Dalitz.20100216.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrROT13V10 (strString)
strTableIn = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
strTableOut = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
Return udfStrTranslateV4 (strString, strTableOut, strTableIn, "")
;..........................................................................................................................................
; This UDF "udfStrROT13" accepts a string and returns the ROT-13 encoded/decoded string.
; For example `ABC 123 xyz` becomes `NOP 123 klm` and vice-versa.
;
; Detlev Dalitz.20100202.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrTranslateV4 (strString, strTableOut, strTableIn, strPad)
If strTableOut == "" Then If strTableIn == "" Then Return StrUpper (strString)
If strPad == "" Then strPad = " "
arrT = ArrDimension (256)
For intI = 0 To 255
   arrT [intI] = intI
Next
arrS = ArrayFromStr (strString)
arrI = ArrayFromStr (strTableIn)
arrO = ArrayFromStr (StrFix (strTableOut, strPad, ArrInfo (arrI, 1)))
intLast = ArrInfo (arrI, 1) - 1
For intI = 0 To intLast
   arrT [Char2Num (arrI[intI]) ] = Char2Num (arrO[intI])
Next
intLast = ArrInfo (arrS, 1) - 1
For intI = 0 To intLast
   arrS[intI] = Num2Char (arrT [Char2Num (arrS[intI]) ])
Next
Return ArrayToStr (arrS)
;..........................................................................................................................................
; Detlev Dalitz.20100202.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Performance Test.

strString = "[{# ABC -- WinBatch rotates *You* -- XYZ !}]"

intTestMin = 1
intTestMax = 10
intLoop = 10

For intT = intTestMin To intTestMax

   Exclusive (@ON)
   intStart = GetTickCount ()

   For intL = 1 To intLoop
      strROT = udfStrROT13V%intT% (strString)  ; "# NOP -- JvaOngpu ebgngrf *Lbh* -- KLM !"
      strROTROT = udfStrROT13V%intT% (strROT)  ; "# ABC -- WinBatch rotates *You* -- XYZ !"
   Next

   intStop = GetTickCount ()
   Exclusive (@OFF)
   intTicks%intT% = intStop - intStart

Next


:Result
intMax = 0
For intT = intTestMin To intTestMax
   intMax = Max (intMax, intTicks%intT%)
Next
For intT = intTestMin To intTestMax
   intPct%intT% = 100 * intTicks%intT% / intMax
Next

strMsgTitle = "Demo Performance Test  udfStrROT13 (strString)"
strMsgText = ""
For intT = intTestMin To intTestMax
   strMsgText = StrCat (strMsgText, "Test ", intT, @TAB, intTicks%intT%, @TAB, intPct%intT%, "%%", @LF)
Next
Message (strMsgTitle, strMsgText)
ClipPut (strMsgText)
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
;   Test  1    7422    81%
;   Test  2    8797    96%
;   Test  3    7235    79%
;   Test  4    4906    53%
;   Test  5    5453    59%
;   Test  6    3312    36%     <== The winner.
;   Test  7    6422    70%
;   Test  8    5016    54%
;   Test  9    5250    57%
;   Test 10    9156   100%
;------------------------------------------------------------------------------------------------------------------------------------------