I'm making a very simple encrypter in C# which is basically a Stream cipher. The user enters a key(password), converted to a seed for a pseudo-random generator, and the pseudo-random generator generates the numbers used to shift the characters. The decrypt process goes the same, but then in inverse.
Here's the pseudo-code I use:
1. Get the characters 2. Initialize a seed with the value 0 3. Loop through each character, adding the characters' value to the seed 4. Return the seed
But that has a problem. What if I have a (poor) password, like
The encrypted output would be the same if I used
You can write this password in
5! = 120 ways. That's not good!
So I came up with a solution:
1. Get the characters 2. Initialize a seed with the value 0 3. Loop through each character, adding the characters' value times it's position to the seed 4. Return the seed
But that's not good either. With a large password, you would get huge skips in numbers if you modify the last number. That's bad, because you want the most permutations possible for a random number generator.
Last character(12) has a value of 10 10 * 12 = 120 Then you change it to 11 11 * 12 = 132 ^ gap of 12
Then I changed
step 4 into this:
4. Return the seed divided by the length of the key
That's not a good option either, because with large passwords it wouldn't really matter what the value was of the first character in order to make a difference.
Password size: 10 1/10 = 0 8/10 = 0
So what's a good method for user-based passwords?