-1

In my one application i want to shuffle string contents and in another application if i pass this shuffled string as input then that application has to return original string value.Is there any method is available to do this in dotnet plateform?

Praveen Kumar
  • 1,576
  • 8
  • 31
  • 47

2 Answers2

2

you can use Fisher–Yates shuffle algorithm.

it is an algorithm for generating a random permutation of a finite set—in plain terms, for randomly shuffling the set.

The basic method given for generating a random permutation of the numbers 1–N goes as follows:

  1. Write down the numbers from 1 to N.
  2. Pick a random number k between one and the number of unstruck numbers remaining (inclusive).
  3. Counting from the low end, strike out the kth number not yet struck out, and write it down elsewhere.
  4. Repeat from step 2 until all the numbers have been struck out.
  5. The sequence of numbers written down in step 3 is now a random permutation of the original numbers.

there is an example : shuffle algorithm

and good one here

Community
  • 1
  • 1
KF2
  • 9,887
  • 8
  • 44
  • 77
1

Definitely not out of the box, but create yourself a struct

struct ShuffleChar{
    char c;
    int index;
}

and when you shuffle your letters, assign each letter an index so you can put them together again. Remember, a string only makes sense if the letters are in the correct order, changing that order will destroy that information and with high probability you cannot restore it...

bash.d
  • 13,029
  • 3
  • 29
  • 42