HTML/SGM/XHTML/XML element values obfuscator script

HTML/SGM/XHTML/XML element values obfuscator script

74
Advanced UserAdvanced User
74

    Mar 02, 2021#1

    Can anyone write up a script that will "scramble/obfuscate" text in SGM|XML|HTML files. I need to send some documents to a vendor but the documents must not contain its original data. The file will retain it's markup and any attribute markup.

    Attached is a demo.sgm file.

    Thank you,
    Maxine
    demo.sgm (263.61 KiB)   0
    SGM file to obfuscate

      Mar 03, 2021#2

      I've got this code almost working. It selects the text between >< and scrambles it, but I can't get the loop working, so I just keeps changing the same line over and over again.

      Code: Select all

      while(UltraEdit.activeDocument.findReplace.find(">(.*?)<\/")) {
          var sShuffle = UltraEdit.activeDocument.selection.replace(/>(.*?)<\//, "$1");
          var textShuffled = sShuffle.split('').sort(function () {
                  return 0.5 - Math.random()
              }).join('');
          UltraEdit.activeDocument.findReplace.replace(sShuffle, textShuffled);
      }

      6,688586
      Grand MasterGrand Master
      6,688586

        Mar 03, 2021#3

        I suggest this script which selects just XML element values within a line with at least two characters and shuffles the characters. The Perl regular expression find does not select multi-line values of an XML element.

        Code: Select all

        if (UltraEdit.document.length > 0) {
           UltraEdit.insertMode();
           if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
           else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
           UltraEdit.activeDocument.top();
        
           UltraEdit.perlReOn();
           UltraEdit.activeDocument.findReplace.mode=0;
           UltraEdit.activeDocument.findReplace.matchCase=true;
           UltraEdit.activeDocument.findReplace.matchWord=false;
           UltraEdit.activeDocument.findReplace.regExp=true;
           UltraEdit.activeDocument.findReplace.searchDown=true;
           UltraEdit.activeDocument.findReplace.searchInColumn=false;
        
           while(UltraEdit.activeDocument.findReplace.find(">\\K(.{2,}?)(?=</)")) {
              var sShuffle = UltraEdit.activeDocument.selection;
              var textShuffled = sShuffle.split('').sort(function () {
                      return 0.5 - Math.random()
                  }).join('');
              UltraEdit.activeDocument.write(textShuffled);
           }
        }
        
        Another script which supports also multi-line XML values:

        Code: Select all

        if (UltraEdit.document.length > 0) {
           UltraEdit.insertMode();
           if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
           else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
           UltraEdit.activeDocument.top();
        
           UltraEdit.perlReOn();
           UltraEdit.activeDocument.findReplace.mode=0;
           UltraEdit.activeDocument.findReplace.matchCase=true;
           UltraEdit.activeDocument.findReplace.matchWord=false;
           UltraEdit.activeDocument.findReplace.regExp=true;
           UltraEdit.activeDocument.findReplace.searchDown=true;
           UltraEdit.activeDocument.findReplace.searchInColumn=false;
        
           while(UltraEdit.activeDocument.findReplace.find("(?<!--)>\\K([^<]{2,}?)(?=</)")) {
              var sShuffle = UltraEdit.activeDocument.selection;
              if (sShuffle.replace(/^[\r\n\t ]+$/,"").length) {
                 var textShuffled = sShuffle.split('').sort(function () {
                         return 0.5 - Math.random()
                     }).join('');
                 textShuffled = textShuffled.replace(/\r/g,"");
                 textShuffled = textShuffled.replace(/\n/g,"\r\n");
                 UltraEdit.activeDocument.write(textShuffled);
              }
           }
           UltraEdit.activeDocument.top();
        }
        
        Both scripts are definitely not foolproof and do not work for any XML file contents.
        Best regards from an UC/UE/UES for Windows user from Austria

        74
        Advanced UserAdvanced User
        74

          Mar 12, 2021#4

          Mofi I'm having issues with the script selecting element when they occur within another element. I'm using your scramble javascript (the first one)

          Example SGML/XML

          Code: Select all

          <entry rowsep="1">14</entry>
          <entry rowsep="1">Ready made ice cream</entry>
          <entry rowsep="1">Displays voltage, amperage.</entry></row>
          <row>
          <entry rowsep="1">15</entry>
          <entry rowsep="1">Power Phase</entry>
          <entry rowsep="1">Glowing indicator:<randlist>
          <item>Max &ndash; Maximum</item>
          <item>Min &ndash; Minimum</item>
          <item>LM1 &ndash; Limit 1</item>
          <item>LM2 &ndash; Limit 2</item>
          <item>THD &ndash; Total Ice Cream flavors</item>
          <item>K &ndash; K-factor</item></randlist></entry></row>
          <row>
          <entry rowsep="1">8</entry>
          <entry rowsep="1">Limit (Red)</entry>
          <entry rowsep="1">Illuminates </entry></row>
          <row>
          <entry rowsep="1">9</entry>
          <entry rowsep="1">Normal/Hi Temp</entry>
          <entry rowsep="1">Illuminates when the return oven<acronym><def>Chocolate is the best</def>
          <term>FDECU</term></acronym> is at or above 90 &deg; <acronym><def>Fahrenheit</def>
          <term>F</term></acronym> (32 &deg; <acronym><def>Celsius</def>
          <term>C</term></acronym>). Becareful when eating hot cookies.</entry></row>
          <row>
          Thank you for the help

            Mar 15, 2021#5

            Another issue I'm having if two start or end tags are in a single line it adds text between it.  Eg <table><row> and </entry></row> creates text between the elements...creating <table>xxx<row> and xxx</entry>xxxxx</row> I'm guessing I need a better Pear expression using look arounds and I suck at those. Your help is appreciated.

            Max

              Mar 26, 2021#6

              Attached is the working code.
              Scramble2.zip (486 Bytes)   0
              Working obfuscator script