Scrambling Text

I had a request to write a script that would take a text document with multiple frames and scramble its text. There was a desire to share the document regarding its layout, but not the actual content. While the text could have been replaced by lorem ipsum, this would have been time-consuming, and various styles would have to be recreated.

Here is the initial version of this script, which scrambles the text in a selected frame, which must of course be a text frame. The logic begins with the way that Autoquote takes apart the content of a frame, character by character, but skipping over the characters you're not looking for, leaving everything else, including the markers for character styles, intact.

Here we wish to change all aphabetical characters, but leave numbers, punctuation, carriage returns, and so on unchanged. It uses the python module random to generate a new random small letter and capital letter each time a new alphabetical character is found, then modifies according to the case of the found letter. This isn't like a cryptographic code using some algorithm for the process, it's as random as the random module can generate, so this will not be reversible. This isn't exactly true – there are some times when you can use Undo after running the script to see what I mean. Once you save the document and reopen, it's truly irreversible.

Todo
Update:  Done! Look for the message in the lower left corner of the main window. Pretty cool – I'll have to remember this for the future. Note that you don't ever see a "Processing Page 1" message, only page 2 and after. To compensate I added something early that says, "Getting ready to process Page 1" that comes up with the dialog.
 * Add a progress bar
 * I don't think a progress bar is feasible. I think having repeated messageBoxes would be too disruptive, but IIRC there is a command for sending a message to the bar at the bottom of the main window. I've never tried it, but perhaps it's worth a try.
 * Possibility to scramble text on master pages
 * Should be doable (I think).
 * Possibility to scrambled text of grouped text objects on master pages
 * Hmm, more challenging.
 * Scramble image names
 * Now this takes some research ... I think a barrier here will be that if you scramble image names with a script you create a missing image problem. Maybe easier just to remove all images?

replacetext_v3.py
The next phase was to try not to simply alter all the text in all the text frames and all pages of a document. Here is the final result.

I have added a warning message and an ability to opt out of the script in case you haven't saved the original.

replacetext_v2.py
This is another version which only modifies a page at a time.

Side Effects
The biggest one seems to be that in most if not all cases your text will take up more lines than it did before scrambling. This is due to the random nature of these changes, in which case the occurrence of wide letters is much more common than in the anyone's original text. There could certainly be the possibility of considering character frequencies and making adjustments, but this would reduce randomness somewhat.

Also note that as written this changes only the limited Latin character set, a-z, and A-Z, but you should be able to alter this script to include other character sets. One might also scramble numbers to random numbers if that seemed desirable.