What is a simple, reversible, non-cryptographic string cypher function with excellent avalanching?

Viewed 82

I need to implement a pair of functions to obfuscate / deobfuscate a string, in the form:

  • string cipher(string plainText, string secret)

  • string decipher(string cipherText, string secret)

I need them to be terse and simple to implement. I am hoping for e.g. about a page of code or less that I will embed in my code body with no special dependencies. I will need to implement this in C# and vanilla JavaScript in-browser.

This does not need to be cryptographically secure; it is totally OK if it is trivial to hack.

Most of all I am looking for a function with excellent avalanching, i.e. small changes to the plain text input result in drastically different cipher text output.

I am considering a few possibilities, including XTEA and NTSA. But what I have seen so far is small changes e.g. to the end of the plain text result only in (somewhat) small changes to the end of the cipher text. Hence the changes appear to be localized. This is not great for my use, where the plain text will include an ever-incrementing timestamp as its main source of entropy.

What is a good function or algorithm to achieve this, without resorting to large bodies of code or dependencies?

1 Answers

I think I have decided on XXTEA prefaced with a random number salt prefix, which appears to give excellent avalanching. Thank you @Christopher for reminding me about this technique.

Related