ahkscript / libcrypt.ahk

A collection of crypting and encoding functions from the community
MIT License
66 stars 19 forks source link

Rotx by derRaphael #7

Closed hi5 closed 9 years ago

hi5 commented 9 years ago

derRaphael posted rotx (rot5, 13 and 47) here http://www.autohotkey.com/board/topic/57125-rotx-feat-rot5-rot13-and-rot47/

But for me only 5 & 13 work - the 47 fails with lowercase input so it transforms the H from Hello but leaves ello intact - or is just me?

String is: Hello World #123 ROT13 returns: Uryyb Jbeyq #123 ROT47 should return: w6==@ (@C=5 R`ab

G33kDude commented 9 years ago

Additionally, the input isn't properly sanitized before being RegEx'd. If the input contains \E it'll break

hi5 commented 9 years ago

How about this?

MsgBox % Rot47("Hello World #123") "`nw6==@ (@C=5 R``ab"
MsgBox % Rot47("The Quick Brown Fox Jumps Over The Lazy Dog.") "`n`%96 ""F:4< qC@H? u@I yF>AD ~G6C `%96 {2KJ s@8]"

; adapted from http://langref.org/fantom+java+scala/strings/reversing-a-string/simple-substitution-cipher
; from decimal 33 '!' through 126 '~', 94 
Rot47(string) 
    {
     Loop Parse, string
        {
         c := Asc(A_LoopField)
         c += (c >= Asc("!") && c <= Asc("O") ? 47 : (c >= Asc("P") && c <= Asc("~") ? -47 : 0))
         s .= Chr(c)
        }
     Return s
    }

; by Raccoon July-2009
; http://rosettacode.org/wiki/Rot-13#AutoHotkey
Rot13(string)
    {
     Loop, Parse, string
        {
         c := asc(A_LoopField)
         if (c >= 97) && (c <= 109) || (c >= 65) && (c <= 77)
            c += 13
         else if (c >= 110) && (c <= 122) || (c >= 78) && (c <= 90)
            c -= 13
         s .= Chr(c)
        }
     Return s
    }
joedf commented 9 years ago

Added in, implemented the rot5 and rot18. Thanks :+1: