Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>using System; using System.Linq; using System.Xml.Linq; using System.Collections.Generic; namespace App { class Scrambler { public static void ScrambleTextNodes(XContainer xml) { foreach (XText textNode in GetDescendantTextNodes(xml)) textNode.Value = Scramble(textNode.Value); } public static void UnScrambleTextNodes(XContainer xml) { foreach (XText textNode in GetDescendantTextNodes(xml)) textNode.Value = UnScramble(textNode.Value); } public static IEnumerable&lt;XNode&gt; GetDescendantTextNodes(XContainer xml) { return xml.DescendantNodes().Where(node =&gt; node.NodeType == System.Xml.XmlNodeType.Text); } public static string Scramble(string s) { var a = s.Select(ch =&gt; (char)(ch + 3)).ToArray(); return new string(a); } public static string UnScramble(string s) { var a = s.Select(ch =&gt; (char)(ch - 3)).ToArray(); return new string(a); } } class Program { static void Main(string[] args) { var doc = XDocument.Parse("&lt;a&gt;&lt;b&gt;this&lt;/b&gt;&lt;b&gt;&lt;c&gt;is&lt;/c&gt;&lt;c&gt;&lt;d&gt;a test&lt;/d&gt;&lt;/c&gt;&lt;/b&gt;&lt;/a&gt;"); Scrambler.ScrambleTextNodes(doc); Console.WriteLine(doc.ToString()); Scrambler.UnScrambleTextNodes(doc); Console.WriteLine(doc.ToString()); Console.ReadLine(); } } } </code></pre> <p>Output:</p> <pre><code>&lt;a&gt; &lt;b&gt;wklv&lt;/b&gt; &lt;b&gt; &lt;c&gt;lv&lt;/c&gt; &lt;c&gt; &lt;d&gt;d whvw&lt;/d&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; &lt;a&gt; &lt;b&gt;this&lt;/b&gt; &lt;b&gt; &lt;c&gt;is&lt;/c&gt; &lt;c&gt; &lt;d&gt;a test&lt;/d&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; </code></pre> <p>You can always use some other scrambling algorithm. The scrambling itself is a translation to C# of Kai's Python answer.</p> <p>edit: clean-up :) edit2: removed the check to not scramble spaces. This would cause the unscrambling to be incorrect at times...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload