-1

I need to scramble chars in word. And this scrambling must not be random. In other words, each time of scrambling (on the same word) the new result must be equal to last scramble result (on the same word). Very simple example is XOR. But XOR is very easy to decode and I need something more strength. Could you recommend library for such purpose that identically works on C# and Javascript?

Thank you for any advice!:)

Edward83
  • 6,664
  • 14
  • 74
  • 102
  • 1
    worrying about strength on such a simple cypher seems pointless... why not just run with ROT13? Any algorithm meeting your spec is not really "stronger"... This isn't rhetorical: understanding the context / thinking is key to suggesting an appropriate device; i.e. what "attack" are you trying to protect this data from? – Marc Gravell Apr 19 '11 at 08:16
  • You don't need to scramble chars in word. You either need to save a word document encrypted (see pgp) or you need something else than a word document. So the real question is: why do _you_ think you need to do this? – sehe Apr 19 '11 at 08:21
  • Thank you! I want to scramble before building md5;) – Edward83 Apr 19 '11 at 08:23

3 Answers3

4

You can use random with fixed seed if you really want to scramble characters:

string input = "hello";
char[] chars = input.ToArray();
Random r = new Random(2011); // Random has a fixed seed, so it will always return same numbers (within same input)
for (int i = 0 ; i < chars.Length ; i++)
{
    int randomIndex = r.Next(0, chars.Length);
    char temp = chars[randomIndex];
    chars[randomIndex] = chars[i];
    chars[i] = temp;
}
return new string(chars);
Snowbear
  • 16,924
  • 3
  • 43
  • 67
  • 2
    Great answer it uses a random object but wont work from Javascript. I would use the first characters from the string to create a randomisation algoritm. – CodingBarfield Apr 19 '11 at 08:23
  • Agree with comment, you'll have to find/write `Random` function in javascript which behaves similarly comparing to C# one. – Snowbear Apr 19 '11 at 08:31
1

Although I don't really agree about what you were trying to do, here's a link to MD5 javascript library (assuming what you're trying to do is some kind of encryption). As for the C# part, it's a built in feature.

Salamander2007
  • 6,294
  • 8
  • 32
  • 26
1

You can use any of the built in .NET classes to generate random numbers and use these to scramble your string. For all the subsequent scramble attempts you can use the result from the first scramble operation. This assumes that the result from the first call is stored somewhere.

Ramki
  • 315
  • 3
  • 8