I want to run through multiple algorithms against an encrypted string. I have the password and the encrypted string but not the method it was encrypted under?

what would be the best method to find out the method short of going through every method manually.

  • 1
    Not really - there are too many variables. For example, assuming the string was encrypted using AES, which mode was used (CBC ECB CTR OCB CFB)? What block length? What if it's using a different algorithm? – Matthew Mar 3 '16 at 12:11
  • 1
    @MarkBuffalo no :< its my flag and i captured it :< get your own flag :< :< :< – TheHidden Mar 3 '16 at 12:14
  • 1
    This might actually be a good idea for an OSS project like hash-identifier but for encryption. – HamZa Mar 3 '16 at 12:19
  • 1
    @agtoever lol dont worry i knew that when i was 15 but thanks – TheHidden Mar 5 '16 at 10:08
  • 1
    @agtoever OP has over 2000 rep and 2 gold badges. I'm pretty certain he knows the difference between encryption and hashing. The question is, why do you think you know he is referring to a hash? – cremefraiche Mar 6 '16 at 13:28

Easy way:
Write a script that tries decryption with openssl using all of the block cipher modes. I would consider using openssl in a BASH script or importing pyOpenSSL (or subprocess) and using try/except blocks in python (or the equivalent in whatever language you are most comfortable in) to get the right mode quickly.

Academic way:
Write a detection oracle.
If you have not read through the Matasano Crypto Challenges before, I would recommend starting at Set 1 and reading about implementing and detecting ECB. Set 2 goes into implementing/detecting CBC and also creating a CBC/ECB detection oracle. Once you understand how the block cipher modes work, it becomes easier to understand how to differentiate them from eachother.

Unfortunately this is where my knowledge currently gets hazy on the subject, so if an ECB/CBC detection oracle does not identify the ciphertext, I would suggest you take a look at this good answer to a similar question. The user explains what you would need to look for in order to identify OFC/CTR and EAX/GCM as well, which you could then use to create a more complete detection oracle.

Update 9-Mar-2016

I have been trying to tackle the problem of identifying block cipher modes of encryption, given ciphertext-only, over the last week. The problem with the answer I referenced (in relation to this goal) is that it assumes knowledge of the key/IV to be able to analyze error propagation. I have read through every cryptography book I own, searched the interwebs, and have asked a question specific to this on crypto.SE.
From this research so far, I have tentatively come to the conclusion that:

  • ECB can be easily and consistently identified, given a ciphertext of a large enough size.
  • Stream Ciphers (CFB, OFB, CTR) can easily be identified if the ciphertext is not an appropriate block length, however I have yet to find a way to differentiate stream ciphers from each other given ciphertext-only.

With this information, a ciphertext of block length (AES=128) can be assumed with ~99.22% certainty (1/128 chance of stream ciphertext being multiple of blocklen = ~0.78 chance) to be a block cipher. From here, the aforementioned detection oracle will be able to detect ECB if it is used. If ECB is not detected, you are left with CBC and PCBC as the two main possibilities. This is the best detection analysis I have come up with so far.

  • 1
    If the IVs have high entropy, then even chosen-plaintext should not suffice for differentiating stream ciphers from [IVs followed by randomness]. ​ ​ – user49075 Mar 10 '16 at 0:47
  • 1
    @cremefraiche: Maybe I'm not understanding something... What exactly is the benefit of a sophisticated cipher oracle vs. just trying to decode something in all of the most common algorithms/ciphers/... etc? I mean, how many are there? Maybe a couple of hundred max? Shouldn't this be fast enough? – fgysin reinstate Monica Mar 10 '16 at 9:24
  • @fgysin For me, just to figure it out. OP has the key, but I'm curious what can be inferred from the ciphertext only approach. Since it really depends on how you judge which approach is better I've adjusted my answer to be less subjective. – cremefraiche Mar 10 '16 at 10:57
  • @cremefraiche: Alright, thanks for clearing this up! – fgysin reinstate Monica Mar 10 '16 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.