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?
Asked
Active
Viewed 446 times
-1
-
do you what to do some thing like Fisher–Yates shuffle? – KF2 Apr 04 '13 at 08:38
-
where is the code you have already done? – Freelancer Apr 04 '13 at 08:39
-
by "application", do you mean "restful services" ? – nurettin Apr 04 '13 at 08:39
-
Why reinvent the wheel? Use encryption/decryption methods. – Shadow The GPT Wizard Apr 04 '13 at 08:41
-
@ShadowWizard that i am already doing..But for security we are going to do this one – Praveen Kumar Apr 04 '13 at 08:43
-
1Shuffle is the wrong term then. By definition it means "change the order **randomly**" so it's not meant to be reversible. – Shadow The GPT Wizard Apr 04 '13 at 08:46
-
Heard of cryptography? – bahrep Apr 04 '13 at 13:29
2 Answers
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:
- Write down the numbers from 1 to N.
- Pick a random number k between one and the number of unstruck numbers remaining (inclusive).
- Counting from the low end, strike out the kth number not yet struck out, and write it down elsewhere.
- Repeat from step 2 until all the numbers have been struck out.
- 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
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
-
-
Like I told you in my answer, try to preserve the information somehow. You can't recreate the original string once you shuffled it, without keeping any information about its origin – bash.d Apr 04 '13 at 08:45