4

I have a int array of considerably large size. I need to shuffle the array completely using a key. I should be able to obtain the original array using the same key. I searched for any shuffle algorithms but the one i found like Fisher Yates does not use a key.

The int array is pixel values of a image. I need to hide data into it. So hiding data after shuffling the array enables accessing of data only if one have the key.

Amar C
  • 374
  • 5
  • 17
  • 2
    You can use Fisher Yates for this, as explained in http://stackoverflow.com/a/3542000/367273 -- BTW, that was the top match on Google for "reversible shuffle". – NPE Mar 25 '13 at 15:53

1 Answers1

2

Fisher-Yates uses a pseudo-random number generator, which you can seed using a key (look for cryptographic PRNGs). To reverse the process, shuffle an array of indices [0, n) using the same key, then perform a reverse shuffle.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • 1
    this is what i came up with `for (int i=0; i < data.length; i++) { j = (j + key[i % key.length]) % data.length; tmp = data[i]; data[i] = data[j]; data[j] = tmp; }` its shuffling the array but cant get the original back. – Amar C Mar 25 '13 at 16:28
  • can you please replay. – Amar C Mar 25 '13 at 17:31