VBScript str_rot13 function

A VBScript equivalent of PHP’s str_rot13


Function str_rot13(str)

    Dim str_rotated : str_rotated = "
    Dim i,j,k

    For i = 1 to Len(str)
        j = Mid(str, i, 1)
        k = Asc(j)
        if k >= 97 and k =< 109 then
            k = k + 13 ' a ... m
        elseif k >= 110 and k =< 122 then
            k = k - 13 ' n ... z
        elseif k >= 65 and k =< 77 then
            k = k + 13 ' A ... M
        elseif k >= 78 and k =< 90 then
            k = k - 13 ' N ... Z
        end if

        str_rotated = str_rotated & Chr(k)
    Next

    str_rot13 = str_rotated

End Function

Please also note that php.vbs offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just:

Other PHP functions in the strings extension