I am fairly new to applescripting and InDesign applescripting and I am looking for some guidance.
I found a simple letter substitution cipher applescript for InDesign that replaces a letter with the letter 13 letters after it in the alphabet. I can’t remember where I found it and couldn’t relocate it when I went searching for it recently.
–set theAlphabet to {“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”, “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”}
tell application “Adobe InDesign CS5.5”
if (count of every document) > 0 then
set theAlphabet to “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
set theROT to “nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM”
– set ReplacementText to “”
–set ReplacementText to the selection
set ReplaceThis to the selection
set ReplacementText to ReplaceThis as string
set WithThis to “”
if ReplacementText is not “” then
–repeat with i from 1 to the count of characters in ReplaceThis
considering case
repeat with eachChar in ReplacementText
– (*
set x to the offset of eachChar in theAlphabet
if x is not 0 then
set WithThis to ¬
WithThis & (character x of theROT) as string
else
set WithThis to (WithThis & eachChar) as string
end if
–*)
end repeat
end considering
set ReplaceThis to item 1 of ReplaceThis
set the contents of ReplaceThis to WithThis --as string
else
display dialog "select some text first"
end if
else
display dialog "you need to select text in an open document"
end if
end tell
The script works well: You select the text you to change, click the script and it does the letter substitution.
I am looking to modify the script so it will use the Fisher-Yates shuffle algorithm instead of the ROT-13 system of letter replacement. This way the substitutions will be unique each time the script is run.
Here is the applescript for the Fisher-Yates algorithm I found:
set myList to {“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”}
–set myList to {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
set answer to listShuffle(myList)
on listShuffle(theList)
set listLength to count of theList
repeat while listLength > 1
set r to random number from 1 to listLength
set item1 to item listLength of theList
set item2 to item r of theList
set item listLength of theList to item2
set item r of theList to item1
set listLength to listLength - 1
end repeat
return theList
end listShuffle
return myList
I have been tooling around with it for a week and realized I am way over my head.
I am not looking for someone to give me a completed solution, but I am hoping someone could point me in the right direction.
Thanks.