Assuming that the request for a “random” allocation of letters to arrays is for a pseudo-random (or, perhaps, a superficially arbitrary) allocation that is therefore reversible, one technique to do this would be to essentially use a transposition cipher.
The algorithm would then be something like:
- Run the transposition cipher on the input text.
- Split the transposed text into the arrays.
The original text would then be obtained by reversing the two steps.
(EDIT)
The transposition cipher key could consist of a stream of pseudo-random numbers from 1
to n
where n
is the number of strings into which the input string is to be split. Thus, an expanded algorithm would read as follows:
- Generate a list of pseudo-random numbers,
p
, of lengthm
, wherem
is the length of the input string. - For all
i
, assign thei
th letter in the input string to the output string numberp[i]
.
To reassemble the original string:
- For all
i
, obtain thei
th letter in the string from the next unused letter in string numberp[i]
.
2
solved is there a way randomly separate a string into different string array and get back same same string [closed]