Given an infinite amount of both unencrypted and the corresponding encrypted text, would I be able to calculate the algorithm? I am relative new to cryptography and don't know if I would be able to find how the unencrypted text is encrypted... Is this possible? If so, what should I study?

  • 5
    $\begingroup$ Do you have an infinite amount of time as well? $\endgroup$
    – cygnusv
    Commented Feb 17, 2015 at 8:23
  • 1
    $\begingroup$ If the encryption is a one-time-pad, no, you can't. For most practical cryptosystems, assuming you also have infinite computational power, yes (or at least you can find something that is as good as the key for any practical purpose). $\endgroup$ Commented Feb 17, 2015 at 8:37
  • $\begingroup$ yes meant the algorithm better... edited my question $\endgroup$ Commented Feb 17, 2015 at 17:02
  • $\begingroup$ removed some comments related to the earlier version of the question $\endgroup$
    – mikeazo
    Commented Feb 18, 2015 at 23:28

2 Answers 2



In general, no. An attacker who has lots of ciphertext+plaintext pairs may never be able to reverse-engineer an algorithm from them. An attack may not even be able to distinguish which one of a large group of known encryption algorithms was used to generate those ciphertexts.

However, various weaknesses in some algorithms and protocols are known. If such an algorithm was used, the attacker may find it relatively easy to rule out all but a few or perhaps only 1 of the known encryption algorithms.


Some people who build modern ciphers try to make their ciphers "indistinguishable from random". Several modern ciphers (especially ones intended for use in steganography) are not currently known to be susceptible to such a distinguishing attack.

No matter how many ciphertext+plaintext pairs the attacker collects that were properly encrypted using a single one of those algorithms using a single long-term key, there is no known practical way for that attacker to distinguish a new message encrypted using the same algorithm using the same long-term key from a freshly generated series of bits from a hardware random-number generator. This implies that there is no known practical way for that attacker to discover which one of those algorithms was actually used.

Cryptanalysts have discovered distinguishing attacks for many vulnerable ciphers. If an attacker collects enough ciphertext-plaintext pairs encrypted by such a vulnerable cipher, that attacker can rule out most other ciphers, narrowing down the possible algorithm to a few or perhaps only 1 known vulnerable encryption algorithm.

When an attacker has samples of both the plaintext (called a crib), and its encrypted version (ciphertext), the attacker can mount a known-plaintext attack.

The people who build modern ciphers try hard to make their ciphers immune to known-plaintext attacks. Most modern ciphers are not currently known to be susceptible to known-plaintext attacks.

However, many historic ciphers (most famously, the Enigma cipher) can be partially or completely broken by a known-plaintext attack.

Many distinguishing attacks and known-plaintext attacks depend on the person doing the encryption using the same key for large numbers of messages. Sometimes that number is so extremely large that these attacks are impractical. Other times that number is large but not improactical, and cryptographers recommend periodically rekeying long before such attacks are practical (RFC4253, RFC4344, etc.).

In practice, many communication protocols transmit the specific encryption protocol used, transmitted in plaintext in the header before any ciphertext, at the beginning of every message. An attacker only needs to look at that header to know which encryption algorithm was used.

If someone encrypts enough messages with the same key using a block cipher in electronic codebook mode, and an attacker gets enough ciphertext-plaintext pairs, then even without knowing which particular block cipher is used, the attacker can decrypt any block in any new encrypted message whenever a block of plaintext in the new message happens to match a block of known plaintext.

In theory, if an attacker has an "infinite amount" of computing power, that attacker try every possible encryption key in every known encryption algorithm and see if it "works". Such a brute-force attack can in theory recover the key for almost all known encryption algorithms. (The one-time pad and closely related ciphers are completely immune to a brute-force attack). Fortunately for people who are not attackers, the amount of work required for such a brute-force attack usually makes them impractical.


Did you know the algorithm ? This is the central question. In modern cryptography, the algorithm is public while the all secret lies in the key. Knowing the algorithm allows analyst to quantify the strength, or the intractability of the mathematical transformation.

You alse have to make a distinction. Two main classes exist between Stream Cipher and Bloc cipher.

In Stream cipher, the key is as long as long as the message, and the question is not well asked. For example OTP case don't recommands to use the same key twice.

In bloc cipher by definition input-output sizes are bounded. for a m-bit cipher size, there are $(2^n)^{2^n}$ binary applications from input space to output space. Then we coudn't have an infinite number of (plain, cipher) pairs.

  • $\begingroup$ ? stream ciphers don't necessarily have keys as long as the message, e.g. see RC4, and block ciphers can have modes of operation that effectively turn them into a stream cipher construction. $\endgroup$
    – Thomas
    Commented Feb 17, 2015 at 9:47
  • $\begingroup$ @Thomas: That's Right! But my answer was to give a general view on the 2 main classes to someone who introduce himself as relatively new in Crypto. No need to give more elaborates constructions at a first glance. $\endgroup$ Commented Feb 17, 2015 at 11:08
  • $\begingroup$ Unfortunately, it looks like your answer caused the OP to change the question :) $\endgroup$
    – mikeazo
    Commented Feb 19, 2015 at 20:01
  • $\begingroup$ @mikeazo: Yes of Course ! I've pointed out that the problem hasn' been mathematically posed. Unfortunately some people hadn't understood. $\endgroup$ Commented Feb 23, 2015 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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