• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple rot-13 encoding script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple rot-13 encoding script


  • Subject: Re: Simple rot-13 encoding script
  • From: Paul Skinner <email@hidden>
  • Date: Fri, 23 May 2003 12:32:26 -0400

On Friday, May 23, 2003, at 07:15 AM, Nigel Smith wrote:

On 21/5/03 19:44, "Marc K. Myers" <email@hidden> wrote:

What's wrong has been pretty well answered. Here's a ROT13 routine
which is much faster and more efficient:

set the clipboard to ROT13(the clipboard as string)

on ROT13(theText)

snip TIDs based ROT13 script

end ROT13

This is a lot longer and 1/5th as fast as my hastily knocked-together
version, below, so I am obviously missing something! What?

return rot("Hello World") of me

on rot(inString)
set outString to ""
set plainChars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
set rotChars to "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
repeat with x from 1 to count of inString
set offsetNum to offset of (character x of inString) in plainChars
if offsetNum > 0 then
set outString to outString & character offsetNum of rotChars
else
set outString to outString & character x of inString
end if
end repeat
return outString
end rot

Nigel

I don't think you're missing anything. It's just preference. Fast on short strings, fast on long strings, balanced for both, low latency, high capacity, short or verbose which one or mixture do you want?
You can usually beat a TIDs based method for doing anything with a simple loop when the data set is small like 'Hello World' but TIDs kick loops butt when you have a lot of data. But then if you get a WHOLE lot of data they break and have to be fed the data in chunks. If you want you could use shell* but then you get a little latency. I find few tasks that the shell doesn't handle well. And the latency is pretty low.
Do shell script does need improvement though. There needs to be a method of passing data to it that isn't limited like 'echo' and isn't file based.

*
On Wednesday, May 21, 2003, at 01:05 AM, Jon Pugh wrote:

set t to do shell script "pbpaste | tr 'a-zA-Z' 'n-za-mN-ZA-M'"
display dialog t buttons "OK" default button "OK"

Sounds like a Harry Potter spell. Pronounced...
Tra zaz nzam nzam!

Handlerized for your protection. Good up to 65000 characters or so.

Rot13("AppleScript looks easy.") -->"NccyrFpevcg ybbxf rnfl."
Rot13(the result) -->"AppleScript looks easy."

on Rot13(t)
set t to do shell script "echo '" & t & "' | tr 'a-zA-Z' 'n-za-mN-ZA-M'"
return t
end Rot13

Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Simple rot-13 encoding script (From: Nigel Smith <email@hidden>)

  • Prev by Date: Re: Crontab message to user
  • Next by Date: Re: Detecting Default PDF reader/writer
  • Previous by thread: Re: Simple rot-13 encoding script
  • Next by thread: Re: applescript-users digest, Vol 3 #1682 - 8 msgs
  • Index(es):
    • Date
    • Thread