0

I have a random binary string s of length l bits. How can I change it in-place to another random string of the same length, such that I can retrieve the original string?

A. A trivial example would be adding +1 modulo 2^l

B. Another example could be: for each bit b in the string, replace it with (b+position(b))%2 where position(b) is the position of the bit (0, 1, 2, 3, ...).

However with both these methods, for every input the output is very similar to the input. For example using method A I'll get '010101' => '010110'. Is there any way to "increase the randomness" of the output somehow? In short, can I randomize a string, and retrieve the original (without adding extra bits to the original string)?

waldo
  • 1

1 Answers1

0

Are you trying to make your own encryption system? If so, typical advice would be to use an existing encryption system.

However, one way to do what you ask, would be to generate a value from the string itself (for example, by taking the length of the string), and using that as a seed to a random number generator, and then using the random number generator to alter each character in some reversible way.

That way, your string will be the same length, and not look like the original, and be decodable. It's not very strong encryption though - just a variable cypher which could be broken by a decent decryption attempt.

Dronz
  • 1,970
  • 4
  • 27
  • 50
  • I'm _not_ trying to write my own encryption system, at least not in the sense that I want to encrypt data. However, looking at your comments encryption might be what I should be looking for. All I'm interested in is a non-trivial "random walk" starting from a given string, and that I can reverse. For example, a trivial random walk will be the simple rule "add +1". So, if I say s="01101", steps=2, the final string will be s="01110". I'd like to know if it's possible to make this "walk" more random while reversible at the same time, for example s="01101", steps=2 => s="11010". Perhaps I can use – waldo Aug 11 '15 at 19:08
  • Yes, well the method I described would do that. When decoding, the length will be the same, so you can get the seed and just subtract that number rather than add, though you'll want to be careful about what your valid range of values is. You could also use a translation map, where you take the ASCII value, add the random number for each character, and then use that number to map to a character that encodes the value to translate back, so decoding requires not just the random number algorithm and constant seed offset, but also the translation table. Basically any reversible process will work. – Dronz Aug 11 '15 at 20:01