Re: Simple rot-13 encoding script
Re: Simple rot-13 encoding script
- Subject: Re: Simple rot-13 encoding script
- From: "Marc K. Myers" <email@hidden>
- Date: Wed, 21 May 2003 14:44:04 -0400
Date: Tue, 20 May 2003 17:27:55 -0700
From: Ashlin Aronin <email@hidden>
Subject: Simple rot-13 encoding script
To: email@hidden
Hello all! I made this simple script to encode rot-13, but it isn't
working. Here's my code:
set currentChar to 1
display dialog "rot-13" with icon note default answer "" buttons
["Cancel",
"OK"] default button 2
if (text returned of result) is not equal to "" then
set the message_text to (text returned of result)
else
display dialog "You didn't enter anything." buttons ["OK"] default
button 1
quit
end if
set AppleScript's text item delimiters to ""
set allChars to every text item of the message_text
repeat until currentChar = (count allChars)
set allChars to replace_chars(item currentChar of allChars, "a",
"n")
set allChars to replace_chars(item currentChar of allChars, "b",
"o")
set allChars to replace_chars(item currentChar of allChars, "c",
"p")
set allChars to replace_chars(item currentChar of allChars, "d",
"q")
set allChars to replace_chars(item currentChar of allChars, "e",
"r")
set allChars to replace_chars(item currentChar of allChars, "f",
"s")
set allChars to replace_chars(item currentChar of allChars, "g",
"t")
set allChars to replace_chars(item currentChar of allChars, "h",
"u")
set allChars to replace_chars(item currentChar of allChars, "i",
"v")
set allChars to replace_chars(item currentChar of allChars, "j",
"w")
set allChars to replace_chars(item currentChar of allChars, "k",
"x")
set allChars to replace_chars(item currentChar of allChars, "l",
"y")
set allChars to replace_chars(item currentChar of allChars, "m",
"z")
set allChars to replace_chars(item currentChar of allChars, "n",
"a")
set allChars to replace_chars(item currentChar of allChars, "o",
"b")
set allChars to replace_chars(item currentChar of allChars, "p",
"c")
set allChars to replace_chars(item currentChar of allChars, "q",
"d")
set allChars to replace_chars(item currentChar of allChars, "r",
"e")
set allChars to replace_chars(item currentChar of allChars, "s",
"f")
set allChars to replace_chars(item currentChar of allChars, "t",
"g")
set allChars to replace_chars(item currentChar of allChars, "u",
"h")
set allChars to replace_chars(item currentChar of allChars, "v",
"i")
set allChars to replace_chars(item currentChar of allChars, "w",
"j")
set allChars to replace_chars(item currentChar of allChars, "x",
"k")
set allChars to replace_chars(item currentChar of allChars, "y",
"l")
set allChars to replace_chars(item currentChar of allChars, "z",
"m")
currentChar = currentChar + 1
end repeat
display dialog allChars buttons ["OK"] default button 1
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
Can anyone tell me what's wrong?
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)
-- the "plaintext" characters for comparison
set compStrng to
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
-- the "encrypted" characters
set replStrng to
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
-- turn the strings into lists
set compList to characters of compStrng
set replList to characters of replStrng
-- a never-used character used to tag each plaintext character.
Only tagged
-- characters will be converted. After conversion the tag is
removed so
-- the character will not get re-converted in subsequent passes
set theFlag to ASCII character 215
-- convert the plaintext to a list
set theText to characters of theText
set AppleScript's text item delimiters to {theFlag}
-- convert the plaintext back to text but with each character
tagged with theFlag
set theText to theFlag & (theText as text) -- flag each character
-- repeat for each character (upper and lowercase) of the alphabet
repeat with i from 1 to count compList
-- check for combination of the flag & alpha character
set AppleScript's text item delimiters to theFlag & (item i of
compList)
set theText to text items of theText
-- replace with new alpha character w/o flag
set AppleScript's text item delimiters to (item i of replList)
set theText to (theText as string)
end repeat
-- remove flags from non-alphabetic characters
set AppleScript's text item delimiters to {theFlag}
set theText to text items of theText
set AppleScript's text item delimiters to {""}
set theText to theText as text
return theText
end ROT13
Marc [05/21/03 2:43:10 PM]
_______________________________________________
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.