Robert Wessel said:
On Sun, 4 Aug 2013 23:00:22 -0700 (PDT), Malcolm McLean
42:13 -0700, Keith Thompson <
[email protected]>
His choice of key[] and txt[] for array names suggests some kind of
cryptographic experiment.
It's possible to write a reasonable-strength encryption program with
srand(), rand and the exclusive or operator. But it's better to
implement
your own rand() to ensure portability.
Only for some extremely generous definitions of "reasonable"!
Almost all srand/rand implementations are LCGs, and have very small
seeds ("keys" - typically 32 bits), and brute forcing them is fairly
trivial. Even worse, LCG PRNGs have terrible cryptographic
properties, so brute forcing them is really doing it the hard way.
Usually simple frequency analysis will do the trick.
So that might keep your kid sister out of your diary, but no one else.
Let's focus on that brute force approach for a minute. One result is
atackatdawn another result is sueforpeace. Which result do you choose as
the proper "cracking" of the code? Or does brute force mean something
else?
Brute force in the context of encryption means trying all possible
keys to see which produces likely messages. For example, if you
intercepted a message encrypted with the described scheme sent between
two English speakers, you could simply try all 2**32 possible keys,
and filter out all of those keys that did not result in a large number
of the strings on contiguous characters match a list of the 10,000
most common English words.
Obviously a sufficiently long message is required to apply any
statistical technique.
If your key is actually as long or longer than the message (as it
would be in your example, where you have a single bit of message), you
have something along the lines of an OTP, which is provable secure.
If, OTOH, you're transmitted your one bit message with massive
redundancy, (say, by sending "attackatdawn" or "sueforpeace_" instead
of the single bit), and you have a short key, you again end up with a
very strong chance that the attacker can decode the message.