VISVESVARAYA TECHNOLOGICALUNIVERSITY
“JnanaSangama”, Belgaum -590014, Karnataka.
CRYPTOGRAPHY AAT
Report On
“BLOWFISH CIPHER”
Submitted by
Navirath HN (1BM23CS206)
Naveen Kumar P N(1BM23CS205)
Mahantesh V N (1BM23CS175)
Mithun M (1BM23CS192)
Under the guidance of
Prof. Syed Akram
Assistant Professor
Dept. Of CSE, BMSCE
in partial fulfilment for the award of the degree of
BACHELOR OF ENGINEERING
in
COMPUTER SCIENCE AND ENGINEERING
B.M.S. COLLEGE OF ENGINEERING
(Autonomous Institution under VTU)
BENGALURU-560019
Feb 2025- June 2025
B. M. S. College of Engineering,
Bull Temple Road, Bengaluru 560019
(Affiliated To Visvesvaraya Technological University, Belgaum)
Department of Computer Science and Engineering
CERTIFICATE
This is to certify that the AAT work entitled “Blowfish cipher” is carried out by Navirath HN
(1BM23CS206), Naveen Kumar PN(1BM23CS205), Mahantesh VN(1BM23CS175),Mithun
M(1BM23CS192) who are bonafide students of B.M.S. College of Engineering. It is in partial
fulfilment for the award of Bachelor of Engineering in Computer Science and Engineering of
the Visveswaraya Technological University, Belgaum during the year 2024-2025. The AAT
report has been approved as it satisfies the academic requirements in respect of Cryptography
(23CS4ESCRP) work prescribed for the said degree.
Signature of the Guide Signature of the HOD
Prof. Syed Akram Dr. Kavitha Sooda
Assistant Professor Prof.& Head, Dept. of CSE
BMSCE, Bengaluru BMSCE, Bengaluru
B.M.S. COLLEGE OF ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
DECLARATION
We, Navirath H N (1BM23CS206) Mahantesh V N(1BM23CS175) Naveen Kumar
PN(1M23CS206) Mithun M (1BM23CS192) students of 4th Semester, B.E, Department of
Computer Science and Engineering, B. M. S. College of Engineering, Bangalore, hereby declare
that, this AAT entitled "Blowfish cipher" has been carried out by us under the guidance of Pradeep
S, Assistant Professor, Department of CSE, B. M. S. College of Engineering, Bengaluru during
the academic semester April 2025-August 2025.
We also declare that to the best of our knowledge and belief, the development reported
here is not from part of any other report by any other students.
Signature
Navirath HN (1BM23CS206)
Naveen Kumar P N(1BM23CS205)
Mahantesh V N (1BM23CS175)
Mithun M (1BM23CS192)
Chapter 1
Introduction
Blowfish Cipher
Blowfish is a symmetric key block cipher known for its efficiency and security, making it an
important tool in the realm of cryptography. It is optimized for speed, which makes it suitable for
applications requiring high performance, and it supports variable-length keys ranging from 32 bits
to 448 bits, providing flexibility in security levels. As of now, no practical attacks have been
successful against the full 16-round version of Blowfish, which has contributed to its widespread
adoption in various applications, such as file encryption, secure shell (SSH), virtual private
networks (VPNs), and password protection through hashing algorithms like bcrypt.
1.1 Problem Statement.
Design and implement the Blowfish cipher, a symmetric-key block cipher, for encrypting and
decrypting data. The implementation should include key generation, encryption, and decryption
functionalities following the specifications of the Blowfish algorithm.
1.2 Motivation.
The motivation behind this problem statement lies in understanding and implementing a
fundamental symmetric-key block cipher, enhancing knowledge of cryptographic algorithms, and
gaining practical skills in secure data encryption and decryption techniques. Blowfish, despite its
age and supersession by newer algorithms like AES, remains relevant for educational purposes and
understanding the evolution of cryptographic techniques. Implementing Blowfish from scratch
provides hands-on experience in:
● Understanding Feistel network-based ciphers.
● Grasping key scheduling and round function design in block ciphers.
1
● Handling data block processing and management in encryption and decryption.
● Appreciating security considerations and vulnerabilities in cryptographic algorithms.
In summary, the problem statement involves implementing Blowfish to encrypt and decrypt data,
considering its specifications and security implications, thereby enhancing understanding and
practical skills in symmetric-key cryptography.
1.3 Aspects of the Algorithm Chosen.
1. Feistel Network Structure
a. Design: Blowfish operates as a Feistel network, which splits the block into two
halves and processes each half through multiple rounds of a function that includes
substitution and permutation operations.
b. Function Rounds: Each round involves a key-dependent function that mixes the
input data with parts of the key.
2. Key Schedule
a. Key Expansion: Blowfish generates round keys from an initial key using a key
schedule algorithm. This involves iterating over the key with a pseudo-random
function derived from the mathematical constant pi.
3. Substitution-Permutation Network (SPN)
a. Substitution (S-boxes): Blowfish uses a set of S-boxes for substitution operations.
These S-boxes are initialized with specific constant values derived from the
hexadecimal digits of pi.
b. Permutation (P-boxes): Blowfish uses P-boxes to rearrange the data within the
block, providing diffusion and confusion in the encryption process.
2
4. Security Features
a. Strengths: Blowfish is designed to resist known cryptanalytic attacks such as
differential and linear cryptanalysis, which were prevalent during its development
period.
b. Key Size: It supports variable key lengths from 32 bits to 448 bits, making it
adaptable to different security requirements.
5. Performance Considerations
a. Efficiency: Blowfish is known for its fast encryption and decryption speed in
software implementations, due in part to its simplicity and the precomputed Sboxes
and P-boxes.
b. Memory Usage: It requires a modest amount of memory for storing the key
schedule and the S-boxes, making it suitable for environments with limited
resources.
3
Chapter 2
Methodology
Blowfish Implementation
1. Key Expansion:
a. Initialize P-array and S-boxes: The P-array consists of 18 32-bit subkeys, and there
are four S-boxes, each with 256 entries.
b. Key Mixing: The user-provided key is used to modify the initial values of the Parray
and S-boxes. This process involves XORing the key with the P-array and using the
Blowfish algorithm to further mix the P-array and S-boxes.
2. Encryption:
a. Divide Plaintext: Split the plaintext into two 32-bit halves (left and right).
b. Initial XOR: XOR the left half with the first subkey (P1).
c. Round Function (16 Rounds):
i. For each round, apply the F function to the left half. ii. XOR
the result with the right half. iii. Swap the left and right halves.
iv. XOR the new left half with the next subkey (P2, P3, ..., P16).
d. Feistel Function:
i. Input: The Feistel function FFF takes a 32-bit input RRR and a subkey
KKK for the current round. ii. Expansion: The 32-bit input RRR is
expanded into a 48-bit value through a specific expansion function.
iii. Subkey Mixing: The expanded value is XORed with the round subkey
KKK.
iv. Substitution: The result is divided into four 8-bit segments, each of which
is used as input to one of four substitution boxes (S-boxes). Each Sbox
outputs a 32-bit value.
4
v. Permutation: The four 32-bit outputs from the S-boxes are combined in a
specific manner and permuted to produce a final 32-bit output.
e. Final Swap and XOR: After 16 rounds, swap the left and right halves and XOR the
right half with the P17 and left half with P18.
f. Combine Halves: Concatenate the left and right halves to get the ciphertext.
3. Decryption:
a. Decryption is similar to encryption but uses the P-array in reverse order. The same steps
are followed, starting with the ciphertext and reversing the key schedule.
5
Flow Chart
Fig 2.1: Flowchart Diagram with Feistel Function Box
6
Chapter 3
Results and Discussion
Fig 3.1: Standard Encryption and Decryption with 64-bit key
The image represents an encryption and decryption process. We can see the following elements:
● Plain Text: "sometext"
● Ciphertext: "f351053d1dd05ac6"
● Key: “aabb09182736ccdd”
Fig 3.2: Analysing various
7
Understanding the Data
Dataset containing pairs of hexadecimal values. One value in each pair is labelled "Plaintext" and
the other "Ciphertext".
Searching for Collisions
To find collisions, we need to identify instances where different plaintexts result in the same
ciphertext. This would indicate a weakness in the encryption algorithm or a potential attack vector.
Steps Involved:
1. Data Preprocessing:
a. Convert the hexadecimal values to their corresponding binary or decimal
representations for easier manipulation.
b. Organize the data into a suitable structure (e.g., dictionary, list of tuples) for efficient
searching.
2. Collision Detection:
a. Iterate through the ciphertext values, comparing them to all other ciphertext values.
b. If a match is found, record the corresponding plaintexts as a potential collision.
8
Fig 3.3: Differential Analysis
Data Structure:
● Old Text: The original plaintext, which appears to be a fixed string "attack".
● New Text: A modified version of the plaintext with one character changed.
● Old Ciphertext: The ciphertext corresponding to the "Old Text".
● New Ciphertext: The ciphertext corresponding to the "New Text".
● Differences: The XOR difference between the "Old Ciphertext" and "New Ciphertext",
represented in hexadecimal.
Assumptions:
● The cipher used is Blowfish.
● The goal is to perform differential cryptanalysis on the Blowfish cipher using the
provided data.
9
Differential Cryptanalysis Approach
Differential cryptanalysis is a technique used to analyse the behaviour of a cipher when small
changes are made to the plaintext and the corresponding changes are observed in the ciphertext.
Steps Involved:
1. Data Collection: The provided data gives us pairs of plaintexts and their corresponding
ciphertexts with a single-bit difference.
2. Difference Calculation: The XOR difference between the ciphertexts for each pair is
calculated and recorded.
3. Pattern Analysis: The differences in the ciphertexts are analysed to identify patterns or
correlations.
4. Key Recovery: Based on the observed patterns, attempts are made to recover the key used
for encryption.
Below are the simulation results of running the above algorithms in CrypTool 2:
Fig 3.4 : Differential Cryptanalysis
10
Fig 3.5: Standard Encryption Decryption
11
CODE
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define BLOCK_SIZE 8 // 8 bytes = 64 bits block size
#define NUM_ROUNDS 4 // Number of Feistel rounds
// Simple round function: rotate left by 1 bit, then XOR with key
uint32_t round_function(uint32_t half, uint32_t key) {
return (half << 1 | half >> 31) ^ key;
// Encrypt one 8-byte block
void encrypt_block(uint8_t *block, uint32_t key) {
uint32_t left, right;
// Copy first 4 bytes to left, next 4 bytes to right
memcpy(&left, block, 4);
memcpy(&right, block + 4, 4);
// Perform NUM_ROUNDS of Feistel rounds
for (int i = 0; i < NUM_ROUNDS; i++) {
left ^= round_function(right, key);
right ^= round_function(left, key);
12
// Copy encrypted left and right halves back to block
memcpy(block, &left, 4);
memcpy(block + 4, &right, 4);
// Decrypt one 8-byte block (reverse order)
void decrypt_block(uint8_t *block, uint32_t key) {
uint32_t left, right;
memcpy(&left, block, 4);
memcpy(&right, block + 4, 4);
for (int i = 0; i < NUM_ROUNDS; i++) {
right ^= round_function(left, key);
left ^= round_function(right, key);
memcpy(block, &left, 4);
memcpy(block + 4, &right, 4);
// Print bytes as hex string
void print_hex(uint8_t *data, int length) {
for (int i = 0; i < length; i++) {
printf("%02X ", data[i]);
printf("\n");
13
}
int main() {
char input[256];
uint8_t block[BLOCK_SIZE];
uint32_t key = 0xABCD1234;
printf("Enter text (up to 8 characters): ");
fgets(input, sizeof(input), stdin);
// Remove newline if present
int len = strlen(input);
if (input[len - 1] == '\n') {
input[len - 1] = '\0';
len--;
// Pad input with zeros if less than 8 bytes
memset(block, 0, BLOCK_SIZE);
memcpy(block, input, len < BLOCK_SIZE ? len :
BLOCK_SIZE);
printf("\nOriginal bytes:\n");
print_hex(block, BLOCK_SIZE);
// Encrypt block
encrypt_block(block, key);
printf("\nEncrypted bytes:\n");
print_hex(block, BLOCK_SIZE);
14
// Decrypt block
decrypt_block(block, key);
printf("\nDecrypted bytes:\n");
print_hex(block, BLOCK_SIZE);
// Print decrypted text as string
printf("\nDecrypted text: %s\n", (char *)block);
return 0;
15
Known Plaintext Bruteforce attack
#include <iostream>
#include <vector>
#include <string>
// Simple XOR-based encryption with a full string key
std::string xor_encrypt_decrypt(const std::string& text, const
std::string& key) {
std::string result = text;
size_t key_length = [Link]();
for (size_t i = 0; i < [Link](); ++i) {
result[i] ^= key[i % key_length]; // XOR encryption using the
full string key
}
return result;
}
int main() {
std::string plaintext = "SecretMessage"; // Known plaintext
std::string encryption_key = "password"; // Secret string key
(unknown to attacker)
std::string encrypted = xor_encrypt_decrypt(plaintext,
encryption_key); // Encrypt
std::cout << "Encrypted Text: " << encrypted << std::endl;
// Brute-force search for correct key (testing common passwords)
std::vector<std::string> keyspace = {"password", "123456",
"hello", "StrongKey", "admin", "guest"};
for (const std::string& test_key : keyspace) {
std::string decrypted = xor_encrypt_decrypt(encrypted,
16
test_key);
if (decrypted == plaintext) { // Check if decrypted text
matches known plaintext
std::cout << "[+] Key Found: " << test_key << std::endl;
return 0;
}
}
std::cout << "[-] No key found." << std::endl;
return 1;
}
17
Chapter 4
Conclusion and Future Work
In our analysis of Blowfish, we performed several standard attacks and cryptanalysis
techniques to evaluate its robustness. For standard attacks, we conducted a basic collision
detection, which is particularly useful when using Blowfish as a hashing function. By inputting
different data blocks, we checked for any collisions, and our results showed no collisions,
indicating Blowfish's robustness in this context. Additionally, we executed a brute-force attack
where we tried all possible keys until the correct one was found. Given Blowfish’s large key space
of up to 448 bits, the brute-force attack proved to be impractical with current technology,
reaffirming the cipher's strength against such attacks.
For cryptanalysis, we performed differential cryptanalysis on the full version of the
Blowfish cipher, focusing on its potential vulnerabilities in a reduced-round configuration. Using
a chosen plaintext attack, we selected pairs of plaintexts with specific differences and analysed
their corresponding ciphertexts. This method allowed us to observe how differential cryptanalysis
could exploit weaknesses in reduced-round versions of Blowfish (four rounds or fewer). Our
findings demonstrated that while the full 16-round Blowfish showed strong resistance to
differential cryptanalysis, the reduced-round versions exhibited vulnerabilities that could be
potentially exploited. This underscores the necessity of using the full 16 rounds to ensure optimal
security.
18
References
[1] K. Bhargavan and G. Leurent, "Sweet32: Birthday attacks on 64-bit block ciphers in TLS and
OpenVPN," [Link], [Online]. Available: [Link]
[2] B. Schneier, "Description of a New Variable-Length Key, 64-Bit Block Cipher (Blowfish)," Schneier
on Security, Sept. 1994. [Online]. Available:
[Link]
[3] "Blowfish Algorithm with Examples," GeeksforGeeks, [Online]. Available:
[Link]
[4] "bcrypt - Blowfish file encryption utility for Windows," SourceForge, [Online]. Available:
[Link]
19