3 Replies Latest reply: Jan 28, 2010 7:47 PM by EJP RSS

    Is there a way to crack this file encryption code?

      The text below is a little irrelevant for the question, it explains how I discovered the code:

      I was randomly making weird binary operations on my notebook (I mean, I REALLY do that, actually...), when I had an idea.
      After a few operations, I found out a way to encrypt files with a password. It was based on operating the original byte with a password in both AND and OR ways, resulting two bytes, then operate them back with: return (byte) ( ( factor & AND ) | ( ( ~factor ) & OR ) );

      It worked, but I a few minutes later I figured it can be cracked by simply decrypting the two bytes with every possible byte and seeing which ones return the same result, then testing these ones with the next AND/OR bytes, and so on until a single byte (or a single sequence) remains. Plus, the encrypted file was twice bigger than the original file.

      Then I thought a little. The two bytes sum sixteen bits, but the result is only eight bits wide, so there are eight bits that aren't used for anything. If I could match the AND and OR bytes by removing the useless bits, I'd get a single encrypted byte, which means the file is the same size as the original and you could not use the strategy I said above, so it's theoretically uncrackable. I figured out the formula in another couple minutes.

      The question itself:

      The formula for generating an encrypted byte is:
      byte res = (byte) ( ( temp & ( ~pass ) ) | ( ( ~temp ) & pass ) );
      //res = the encrypted byte
      //temp = the original byte from the file
      //pass = the password byte
      I also realized that the same formula can be used both for encrypting and decrypting.
      The question is: Is it possible for anyone to crack this without using the "brute force" method?

      Please note I never studied this security stuff before, so I have no clue whatsoever if this formula already exists or something like that (it probably does, somewhere). A book on the issue would really help. Thanks.