I have set up a test app with Blowfish encryption taken from someone else's library. I have been astonished to find that password "Test" gives the same encrypted text as password "TestTestTestTest". Is this normal behavior of the algorithm or is it a bug?

  • $\begingroup$ @forest it does though. Read the keyscheduling code... $\endgroup$ May 28, 2019 at 9:38
  • $\begingroup$ @forest he's not talking about bcrypt, which would give different outputs, but the classic encryption algorithm. $\endgroup$ May 28, 2019 at 9:39

1 Answer 1


It looks like the library is treating the string as the key to Blowfish, which has a veriable key size; the way the keysetup is done (with a cyclical use of the key bytes, see more details on the Wikipedia page) implies that key $k$ of length $n$ and key $k||k$ of length $2n$ have the same expanded key and thus an equivalent encryption/decryption function. Your "Test" example also illustrates this.

Usually from a string a key is "derived" using a KDF, which is then input to an algorithm that accepts keys of some fixed sizes like 128 bits etc. But Blowfish can accept 1 byte keys, and 300 byte keys too, so libraries often don't do this an accept the key input 'as is', without KDF being compulsory. Or they "pad" a string like 'Test' to 16 bytes with 0-bytes etc. Be sure you know what a library does before using it. Keys should be random and unpredictable, not dictionary words.

  • $\begingroup$ So one of the ways is changing the blowfish algorithm to another one? Since the strength of encryption depends on the length of the password, apparently it does not apply to blowfish. For example, the password "TestTestTestA" would have the strength more or less the same as the password TestA? $\endgroup$
    – Mariusz
    May 28, 2019 at 10:42
  • $\begingroup$ @Mariusz TestTestTestA is not equivalent to TestA, as it's not a repeat, TestATestATestA would be. The true solution is to use a KDF. $\endgroup$ May 28, 2019 at 10:47
  • $\begingroup$ I have little knowledge on ciphers. So more or less, regarding the password length, "TestTestTest" has the strength 4 whereas TestTestTestA has the strenght 13 ? $\endgroup$
    – Mariusz
    May 28, 2019 at 11:00
  • $\begingroup$ @Mariusz for this implementation of the cipher, yes. And length is not the only factor of course. $\endgroup$ May 28, 2019 at 11:28
  • 1
    $\begingroup$ A password is not a key. Although Blowfish accepts different key sizes doesn't mean that you should use passwords as key. I agree with Henno here: use a Password Based Key Derivation Function or PBKDF. If you want you could use bcrypt as PBKDF, which uses Blowfish underneath (just an implementation detail). $\endgroup$
    – Maarten Bodewes
    May 28, 2019 at 12:50

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.