views:

834

answers:

10

I wrote an application that encrypts text in this way:

  1. Get the input text

  2. Reverse the text

  3. Convert to hexadecimal

  4. XOR with a key

  5. Base64 encode

Now, I didn't do a lot of encryption/encoding myself, so my question might sound stupid, but, say I get a file which has a content from the above algorithm and I didn't know about this algorithm. How would one start "breaking" the text, are there any guidelines, principals, rules to follow?

My question is not tied to those 5 steps, that was a pure example.

As a different example, take the text: A751CD9E1F99. How would I start investigating what this might mean?

A: 

That is kind of impossible, you'd fail at the XOR decryption if you don't have any knowledge about what key was used.

In a general case, it is even more impossible (if that is possible :)) to gauge what an encrypted string might mean.

Suvesh Pratapa
That is the point of my question. How would you start investigating, poking around? Another example would be how would find out that a text was encrypted with blowfish algorithm?
Alexandru Luchian
It's not kind of impossible, it IS impossible (assuming the key was only used for one message). Check wikipedia for "one time pad"
swampsjohn
Look up cryptanalysis methods online. There are brute force and approximation methods that can help you out. As for the blowfish algorithm, if someone knew whether a text was encrypted with it, there's no point in using it anymore is there?
Suvesh Pratapa
That also assumes that you don't have any knowledge about the plain text (say he encrypted a jpeg instead of text, you could search for header information) and also assumes that the key is the same length as the plain text (if the key were 8 bits (assuming ascii text) then this would really only end up as a substitution cypher).
Niki Yoshiuchi
The idea of a crypto algorithm is that it doesn't matter if somebody knows the algorithm, as long as they don't know the key.
David Thornley
johnswamps, even if the key is used for a single message, it might not qualify as an one time pad (OTP). You also need a bit-for-bit correspondence between the plaintext and the key, so you can't use a 1024-bit OTP to encrypt a 1MiB message safely (every reused bit of the key will be breakable in theory).
Eduard - Gabriel Munteanu
+2  A: 

You'd be able to try guess the algorithm if you know how to decrypt it. I can create many algorithms that would result in "A751CD9E1F99" for some input.

Now, if you have many inputs / outputs available, you could try changing only a little your input to see what happens to the output, for instance. Good encryption algorithms usually result in major output changes for minor input changes.

Samuel Carrijo
+3  A: 

I think you should start by reading The Code Book. What you are asking is how to crack encryption methods and that will give you a start as to how they work.

Kevin
A: 

Err... I'd say:

  1. Base64 decode the output.
  2. XOR the output with the input to get the key.

I'm assuming that since this is a simple encryption algorithm, it should be easy to reverse it this way if you know the input and the output, but not the key.

MiffTheFox
Unless I'm missing something, this sounds like you're acting as if you know the algorithm - but that's the point. You don't know anything about the encoding algorithm at all.
JoeCool
@JoeCool I was using the information provided to me in the question, which helpfully included a copy of the algorithm. I was assuming the question was to reverse-engineer the posted algorithm?
MiffTheFox
+1  A: 

You would need a larger text base than that and some understanding that the crypt is coming from a particular language/domain. Then based on the frequency of words in that language/domain, one could potentially decipher certain attributes form the text.

Of course, good ciphers work around this. Only poorly implemented ciphers can be broken easily with this method.

Ryan Oberoi
+2  A: 

Ciphertext indistinguishability is a good page to start with to understand what crypto algorithms are designed to prevent/defend against. The type of attacks (e.g. IND-CPA) mentioned can also give you a clue about what you can start with.

Rohit
A: 

If you have access to a black box which does the encryption, you can get a lot of information by feeding it particular input values.

As a simple example, if the black box does "one time pad" style encryption, if you feed it all zeroes you get the one time pad. (In fact, feeding it any input value will get you the one time pad with an additional xor.)

Note that good cryptosystems are resistant to such attacks, even if the cryptosystem is already known (but the key is not).

Captain Segfault
Well then it's not a one time pad is it...
Zifre
one refers to the number of times you can safely use it, not the number of times it is actually used! :-)
Captain Segfault
A: 

Rubber-hose cryptanalysis can be quite effective.

Captain Segfault
+6  A: 
erickson
+1  A: 

Basically, this kind of encryption would be reasonable easy to decypher. The base64 encoding would be reasonable easy to recognize. (You'd be using only 64 characters, which is typical for Base64.) Next would be the step to find the original XOR key. that's a bit harder but there are several algorithms that can detect these keys, if there's enough encrypted data available. Your simple text wouldn't be enough but if they know it should become a hexadecimal string, things become a lot easier. Then they have do reverse your other steps. All of them are way too easy.

If possible, it should be able to hack if the hacker knows the original value before encryption. In such cases, a string as short as the one provided could be enough to at least discover your complete encryption routine, although the key you used to XOR the string might not be completely known.

Okay, let's try to decrypt A751CD9E1F99... 12 characters. You only seem to use a few characters so it appears to be just some hexadecimal string. The original must have been 6 characters. Values would be in the range from 0x51 to 0xCD which is too big to use for base64 encoding. Also, since most values are above 0x7F, which suggest that you've done some encoding over it. A dictionary attack could already provide some insight in the XOR key used, where you'd XOR the 6 hexadecimal values with lots of words of 6 characters just to see which one return another word in your dictionary. The ones that seem to return valid words could be the keys you've used to XOR the original. With a second encrypted string, those discovered keys could be used again, filtering the set of possible keys to an even smaller set. On a modern system, such a dictionary attack could return a result within a day.

About 50 years ago, this encryption scheme would be very powerful. Nowadays, expect it to be cracked within a day, by anyone who is interested in trying to decipher it.

I'm not an expert at cracking encryption but I know enough to know which encryption methods are just too weak to use. About 10 years ago, I worked on a project that stored password in an encrypted file using a complex XOR mechanism like yours. A customer then decided to check the security and had a specialist investigate just the passwords files. He only knew one username and password and that user account had no administrative rights. But it was enough information for him to crack that security within an hour, read the information about the administrator accounts and then use that information to just do whatever he liked. My company then gave him free beer for a week... :-) Thus, 10 years ago, a specialist needed just an hour. Nowadays, they're cracking even more complex algorithms with relative ease, simply because computers are way more powerful. If you have to use this kind of encryption then you can just as well use no encryption. It wouldn't really matter for a hacker.

Workshop Alex