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?

 * 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?

Some notes on the versions
I've left all of these here because different users might have different needs.


 * replacetext.py – this one only operates on an individual selected text frame
 * replacetext3.py – this version scrambles the text in all text frames on all pages (but not Master Pages)
 * replacetext4.py – this version scrambles the text in all text frames on all pages AND on all Master Pages
 * replacetext2.py – this version works only on the current page

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_v4.py
Here is a version similar to number 3, but this one in addition will scramble the text in Master Pages. It can probably be made much neater by creating some functions which might be called for the replacement process at least. I decided to be a bit cautious and repetitive in case the Master Page editing didn't work right.

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.