Sign in to follow this  
Followers 0
Paulie

ROT13 Encoding

4 posts in this topic

#1 ·  Posted (edited)

This basically just transposes all alphabetic characters in a string up 13 places, as implied by the name ROTation-13.

Its really simple, but still fun.

Enjoy.

MsgBox(0, "HELLO:", ROT13("HELLO:"));Returns "URYYB:"

Func ROT13($String)
    $Letters = StringSplit($String, "")
    Local $Result = ""
    For $a = 1 to $Letters[0]
        $Char = TransChr($Letters[$a])
        $Result&=$Char
    Next
    Return $Result
EndFunc

Func TransChr($Chr)
    If StringRegExp($Chr, "[a-z]") Then
        $Lower = StringSplit("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz","")
        For $i = 1 to 26
            If $Chr = $Lower[$i] Then 
                Return $Lower[$i+13]
            EndIf
        Next
    ElseIf StringRegExp($Chr, "[A-Z]") Then
        $Upper = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ","")
        For $i = 1 to 26
            If $Chr = $Upper[$i] Then 
                Return $Upper[$i+13]
            EndIf
        Next
    Else
        SetError(1)
        Return $Chr
    EndIf
EndFunc
Edited by Paulie

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Goodie :) I've been looking for something like this

Edited by Bomi

Share this post


Link to post
Share on other sites

Nice, I made one a while ago.

Func _Rot13( $sWord )
    Local $sOriginal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    Local $sNew = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
    Local $sRet
    
    For $i = 1 to StringLen ( $sWord )
        $iPos = StringInStr ( $sOriginal, StringMid ( $sWord, $i, 1 ), 1 )
        If $iPos <> 0 Then
            $sRet = $sRet & StringMid ( $sNew, $iPos, 1 )
        Else
            $sRet = $sRet & StringMid ( $sWord, $i, 1 )
        EndIf
    Next
    
    Return $sRet
EndFunc

A little faster than yours.


[u]My Programs:[/u]Word Search Creator - Make your own Word SearchShortHand - Hide a secret message in a jpg fileHex Editor - Edit your Binary fileIncrease file size - Increase the size of any filesArt Generator - A program that generate random picture[u]My Functions:[/u]16-Bits Hash - My Hash function similar to MD5Probabilities - My probabilities function (factorial, permuation, combination)_GetDate() - Convert a date to a day of the week_Base(), _Dec() - Convert a number in any base (bin, oct, hex, dec). Create your own!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0