Hi, I’ve recently been interested in ciphers, and am wondering if I could use AppleScript to create a scrambler that I could input text into and have it come out scrambled. It would be nice to be able to decode text, but I don’t think that’s possible with AppleScript. Could I create a scrambler with AppleScript, and if so, how? Thanks!
Thanks!
Here’s a simple rotation script to encode/decode:
set Str to words of "Bring the loot to the pub at 7 PM sharp"
set SecretMsg to getCodes(Str)
--> "4589866 37987 822485 1066 37987 30926 65 21 847 47544719"
to getCodes(Str)
set AB to "AB1CD2EF3GH4IJ5KL6MN7OP8QR9ST0UVWXYZ"
repeat with aWord in Str
set n to 0
repeat with aChar in aWord
set n to n * 36 + (offset of aChar in AB)
end repeat
set contents of aWord to n
end repeat
set AppleScript's text item delimiters to space
set code to Str as text
set AppleScript's text item delimiters to ""
return code
end getCodes
set ClearText to decode(SecretMsg)
--> "BRING THE LOOT TO THE PUB AT 7 PM SHARP"
to decode(code)
set AB to "AB1CD2EF3GH4IJ5KL6MN7OP8QR9ST0UVWXYZ"
set CD to {}
set wds to words of (code as text)
repeat with n in wds
set cName to ""
repeat until (n is 0)
set cName to character ((n - 1) mod 36 + 1) of AB & cName
set n to (n - 1) div 36
end repeat
set end of CD to cName
end repeat
set AppleScript's text item delimiters to space
set Ans to CD as text
set AppleScript's text item delimiters to ""
return Ans
end decode