Blowfish Cipher Encryption Algorithm

The Blowfish cipher algorithm is presented based on the algorithm designer Bruce Schneier's technical paper. Blowfish cipher is 16-round and 64-bit block cipher.

Blowfish algorithm was developed by Bruce Schneier in 1993. Here is the Blowfish encryption algorithm presented in Bruce's paper "Description of a New Variable-Length Key, 64-Bit Block Cipher (Blowfish)" at

   T: 64 bits of plaintext
   P{1), P(2), ..., P(18): 18 sub-keys, 32 bits each
   F(): Round function
   C: 64 bits of ciphertext

Algorithm - Blowfish Encryption:
   C = Blowfish(T), Blowfish round process defined as:
      (xL, xR) = T, dividing T into two 32-bit parts
      Loop on i from = 1 to 16
         xL = xL XOR P(i)
         xR = F(xL) XOR xR
         Swap xL and xR
      End of loop
      Swap xL and xR
      xR = xR XOR P(17)
      xL = xL XOR P(18)
      C = (xL, xR), combine xL, xR into 64-bit block

The round function F(A) is defined as:

   A: 32-bit input data
   S1[], S2[], S3[], S4[]: 4 S-box lookup tables, 256 bits each
   B: 32-bit output data

   (a, b, c, d) = A, dividing A into four 8-bit parts
   B = ( (S1[a] + S2[b] mod 2**32) XOR S3[c] ) + S[d] mod 2**32

As you can see from the algorithm, Blowfish is clearly a 16-round and 64-bit block cipher.

See next tutorials on how Sub-keys P{1), P(2), ..., P(18) and S-boxes S1[], S2[], S3[], S4[] are constructed.

Table of Contents

 About This Book

Blowfish Cipher Algorithm

Blowfish Cipher Encryption Algorithm

 Key Schedule (Sub-Keys and S-Boxes) Algorithm

 Efficient Form of the Blowfish Algorithm

 Blowfish Cipher Decryption Algorithm

 Proof of Blowfish Cipher Algorithm

 Blowfish Cipher Test Vectors

 First 8336 Fractional Hex Digits of PI

 piqpr8.c - Generating Hex Digits of PI

 Perl Crypt::Blowfish Module

 Perl Crypt::ECB Perl Module

 Perl Crypt::CBC Module

 Perl Crypt::CFB Perl Module

 OpenSSL "enc -bf-ecb" for Blowfish/ECB Encryption

 OpenSSL "enc -bf-cbc" for Blowfish/CBC Encryption

 OpenSSL "enc -bf-cfb" for Blowfish/CFB Encryption

 OpenSSL "enc -bf-ofb" for Blowfish/OFB Encryption

 PHP Mcrypt Extension for Blowfish

 Blowfish 8-Bit Cipher in PHP


 Full Version in PDF/EPUB