Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you would like something that would be difficult to trace and you don;t mind it being 16 characters, you could use something like this that includes some random numbers and mixes the byte positions of the original input with them: (EDITED to make a bit more untraceable, by XOR-ing with the generated random numbers).</p> <pre><code>public static class OrderIdRandomizer { private static readonly Random _rnd = new Random(); public static string GenerateFor(int orderId) { var rndBytes = new byte[4]; _rnd.NextBytes(rndBytes); var bytes = new byte[] { (byte)rndBytes[0], (byte)(((byte)(orderId &gt;&gt; 8)) ^ rndBytes[0]), (byte)(((byte)(orderId &gt;&gt; 24)) ^ rndBytes[1]), (byte)rndBytes[1], (byte)(((byte)(orderId &gt;&gt; 16)) ^ rndBytes[2]), (byte)rndBytes[2], (byte)(((byte)(orderId)) ^ rndBytes[3]), (byte)rndBytes[3], }; return string.Concat(bytes.Select(b =&gt; b.ToString("X2"))); } public static int ReconstructFrom(string generatedId) { if (generatedId == null || generatedId.Length != 16) throw new InvalidDataException("Invalid generated order id"); var bytes = new byte[8]; for (int i = 0; i &lt; 8; i++) bytes[i] = byte.Parse(generatedId.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber); return (int)( ((bytes[2] ^ bytes[3]) &lt;&lt; 24) | ((bytes[4] ^ bytes[5]) &lt;&lt; 16) | ((bytes[1] ^ bytes[0]) &lt;&lt; 8) | ((bytes[6] ^ bytes[7]))); } } </code></pre> <p>Usage:</p> <pre><code>var obfuscatedId = OrderIdRandomizer.GenerateFor(123456); Console.WriteLine(obfuscatedId); Console.WriteLine(OrderIdRandomizer.ReconstructFrom(obfuscatedId)); </code></pre> <p>Disadvantage: If the algorithm is know, it is obviously easy to break. Advantage: It is completely custom, i.e. not an established algorithm like MD5 that might be easier to guess/crack if you do not know what algorithm is being used.</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