Decrypt / Encrypt String in ROT-13

email me

Converts a string to and from ROT13

Check out encode/decode


Option Explicit

Dim strTestData

strTestData = "This is some test data for ROT13." 


'Before encoding
msgbox "Before encoding: " & strTestData,64,"ROT13"

'After Encoding
strTestData = ROT13Translation(strTestData) 
msgbox "After encoding: " & strTestData,64,"ROT13"

'After Decoding
strTestData = ROT13Translation(strTestData) 
msgbox "After decoding: " & strTestData,64,"ROT13"


Public Function ROT13Translation(stringText)

	Const Characters = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" 
	Dim sROT13Translation, stringPositioning, returnCharacter

	For stringPositioning = 1 To Len(stringText) 
		returnCharacter = Instr(Characters, Mid(stringText, stringPositioning, 1)) 
		If returnCharacter = 0 Then 
			sROT13Translation = sROT13Translation & Mid(stringText, stringPositioning, 1) 
		Else 
			sROT13Translation = sROT13Translation & Mid(Characters, returnCharacter + 13, 1) 
		End If 
	Next 

ROT13Translation = sROT13Translation 

End Function

 

PowerShell


    Clear-Host

    #what to encode
    $rot13string = "ThisIsTheTestString"
    Write-Host Before ecoding: $rot13string

    #after encoding
    $ROT13 = ROT13 $rot13string    
    $rot13string = $ROT13
    Write-Host After ecoding: $ROT13

    #after decoding
    $ROT13 = ROT13 $rot13string
    Write-Host After decoding: $ROT13

    #does translation
    function ROT13 {
    $rot13string.ToCharArray() | ForEach-Object {
        if((([int] $_ -ge 97) -and ([int] $_ -le 109)) -or (([int] $_ -ge 65) -and ([int] $_ -le 77)))
        {
            $string += [char] ([int] $_ + 13);
        }
        elseif((([int] $_ -ge 110) -and ([int] $_ -le 122)) -or (([int] $_ -ge 78) -and ([int] $_ -le 90)))
        {
            $string += [char] ([int] $_ - 13);
        }
        else
        {
            $string += $_
        }        
    }
    return $string
    }