Thomas K
Thomas K

Reputation: 1117

ASP equivalent to strtr PHP function

I'm looking for an ASP equivalent to strtr PHP function. I use it to encrypt in ROT47

This is my PHP code:

function rot47_encrypt($str)
{
  return strtr($str, 
    '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', 
    'PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO'
  );
}

Thank you

Upvotes: 0

Views: 375

Answers (1)

Phylogenesis
Phylogenesis

Reputation: 7880

I believe there is no builtin function to do the same, so it will need to be implemented with a loop.

Something along the lines of:

Public Function rot47(str)
    fromChars = "!""#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
    toChars   = "PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!""#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO"
    rot47     = ""

    For i = 1 To Len(str)
        Position = InStr(fromChars, Mid(str, i, 1))

        If Position = 0 Then
            rot47 = rot47 & Mid(str, i, 1)
        Else
            rot47 = rot47 & Mid(toChars, Position, 1)
        End If
    Next
End Function

Upvotes: 2

Related Questions