
- Cryptography Tutorial
- Cryptography - Home
- Cryptography - Origin
- Cryptography - History
- Cryptography - Principles
- Cryptography - Applications
- Cryptography - Benefits & Drawbacks
- Cryptography - Modern Age
- Cryptography - Traditional Ciphers
- Cryptography - Need for Encryption
- Cryptography - Double Strength Encryption
- Cryptosystems
- Cryptosystems
- Cryptosystems - Components
- Attacks On Cryptosystem
- Cryptosystems - Rainbow table attack
- Cryptosystems - Dictionary attack
- Cryptosystems - Brute force attack
- Cryptosystems - Cryptanalysis Techniques
- Types of Cryptography
- Cryptosystems - Types
- Public Key Encryption
- Modern Symmetric Key Encryption
- Cryptography Hash functions
- Key Management
- Cryptosystems - Key Generation
- Cryptosystems - Key Storage
- Cryptosystems - Key Distribution
- Cryptosystems - Key Revocation
- Block Ciphers
- Cryptosystems - Stream Cipher
- Cryptography - Block Cipher
- Cryptography - Feistel Block Cipher
- Block Cipher Modes of Operation
- Block Cipher Modes of Operation
- Electronic Code Book (ECB) Mode
- Cipher Block Chaining (CBC) Mode
- Cipher Feedback (CFB) Mode
- Output Feedback (OFB) Mode
- Counter (CTR) Mode
- Classic Ciphers
- Cryptography - Reverse Cipher
- Cryptography - Caesar Cipher
- Cryptography - ROT13 Algorithm
- Cryptography - Transposition Cipher
- Cryptography - Encryption Transposition Cipher
- Cryptography - Decryption Transposition Cipher
- Cryptography - Multiplicative Cipher
- Cryptography - Affine Ciphers
- Cryptography - Simple Substitution Cipher
- Cryptography - Encryption of Simple Substitution Cipher
- Cryptography - Decryption of Simple Substitution Cipher
- Cryptography - Vigenere Cipher
- Cryptography - Implementing Vigenere Cipher
- Modern Ciphers
- Base64 Encoding & Decoding
- Cryptography - XOR Encryption
- Substitution techniques
- Cryptography - MonoAlphabetic Cipher
- Cryptography - Hacking Monoalphabetic Cipher
- Cryptography - Polyalphabetic Cipher
- Cryptography - Playfair Cipher
- Cryptography - Hill Cipher
- Polyalphabetic Ciphers
- Cryptography - One-Time Pad Cipher
- Implementation of One Time Pad Cipher
- Cryptography - Transposition Techniques
- Cryptography - Rail Fence Cipher
- Cryptography - Columnar Transposition
- Cryptography - Steganography
- Symmetric Algorithms
- Cryptography - Data Encryption
- Cryptography - Encryption Algorithms
- Cryptography - Data Encryption Standard
- Cryptography - Triple DES
- Cryptography - Double DES
- Advanced Encryption Standard
- Cryptography - AES Structure
- Cryptography - AES Transformation Function
- Cryptography - Substitute Bytes Transformation
- Cryptography - ShiftRows Transformation
- Cryptography - MixColumns Transformation
- Cryptography - AddRoundKey Transformation
- Cryptography - AES Key Expansion Algorithm
- Cryptography - Blowfish Algorithm
- Cryptography - SHA Algorithm
- Cryptography - RC4 Algorithm
- Cryptography - Camellia Encryption Algorithm
- Cryptography - ChaCha20 Encryption Algorithm
- Cryptography - CAST5 Encryption Algorithm
- Cryptography - SEED Encryption Algorithm
- Cryptography - SM4 Encryption Algorithm
- IDEA - International Data Encryption Algorithm
- Public Key (Asymmetric) Cryptography Algorithms
- Cryptography - RSA Algorithm
- Cryptography - RSA Encryption
- Cryptography - RSA Decryption
- Cryptography - Creating RSA Keys
- Cryptography - Hacking RSA Cipher
- Cryptography - ECDSA Algorithm
- Cryptography - DSA Algorithm
- Cryptography - Diffie-Hellman Algorithm
- Data Integrity in Cryptography
- Data Integrity in Cryptography
- Message Authentication
- Cryptography Digital signatures
- Public Key Infrastructure
- Hashing
- MD5 (Message Digest Algorithm 5)
- SHA-1 (Secure Hash Algorithm 1)
- SHA-256 (Secure Hash Algorithm 256-bit)
- SHA-512 (Secure Hash Algorithm 512-bit)
- SHA-3 (Secure Hash Algorithm 3)
- Hashing Passwords
- Bcrypt Hashing Module
- Modern Cryptography
- Quantum Cryptography
- Post-Quantum Cryptography
- Cryptographic Protocols
- Cryptography - SSL/TLS Protocol
- Cryptography - SSH Protocol
- Cryptography - IPsec Protocol
- Cryptography - PGP Protocol
- Image & File Cryptography
- Cryptography - Image
- Cryptography - File
- Steganography - Image
- File Encryption and Decryption
- Cryptography - Encryption of files
- Cryptography - Decryption of files
- Cryptography in IoT
- IoT security challenges, Threats and Attacks
- Cryptographic Techniques for IoT Security
- Communication Protocols for IoT Devices
- Commonly Used Cryptography Techniques
- Custom Building Cryptography Algorithms (Hybrid Cryptography)
- Cloud Cryptography
- Quantum Cryptography
- Image Steganography in Cryptography
- DNA Cryptography
- One Time Password (OTP) algorithm in Cryptography
- Difference Between
- Cryptography - MD5 vs SHA1
- Cryptography - RSA vs DSA
- Cryptography - RSA vs Diffie-Hellman
- Cryptography vs Cryptology
- Cryptography - Cryptology vs Cryptanalysis
- Cryptography - Classical vs Quantum
- Cryptography vs Steganography
- Cryptography vs Encryption
- Cryptography vs Cyber Security
- Cryptography - Stream Cipher vs Block Cipher
- Cryptography - AES vs DES ciphers
- Cryptography - Symmetric vs Asymmetric
- Cryptography Useful Resources
- Cryptography - Quick Guide
- Cryptography - Discussion
Custom Building Cryptography Algorithms (Hybrid Cryptography)
Hybrid cryptography combines two or more encryption techniques. It combines asymmetric and symmetric encryption to take advantage of their respective capabilities. The solution uses public-key cryptography to share keys and symmetric encryption to encrypt messages efficiently.
A hybrid encryption scheme combines the advantages of an asymmetric encryption method with the effectiveness of a symmetric encryption method.
For encryption of a message, initially generate a symmetric key.The person one want to send the message to then share her public key while keeping the secret key private. After that, encrypt the symmetric key with the receiver's public key and transmit it to them.
To decrypt a communication, the receiver decrypts the encrypted symmetric key with the help of her private key to get the decryption key, which she then uses to decode the message.
See the below image to get the visual undersatnding of Hybrid Cryptography:

Here is an explanation of the steps we havementioned in the above image −
- Generate Public & Private Keys − The recipient first creates a pair of keys: a public key and a private key.
- Send Public Key to Sender − The recipient sends his public key to the sender. The public key can be openly distributed as it is used for encryption only.
- Encrypt File with Symmetric Encryption using Public Key Received − The sender wants to send a file securely to the recipient. The sender encrypts the file with the help of symmetric encryption but besides using his own key he uses the recipient's public key. This means that only the recipient who has the corresponding private key can decrypt the file.
- Send Private Key with Asymmetric Cryptogram − The sender now will send the recipient's private key back to him but it is encrypted with the help of asymmetric encryption. This encrypted private key makes sure that only the intended recipient who has the respective private key can decrypt it.
Implementation of Hybrid Cryptography
We will implement Hybrid Cryptography with the help of different programming languages liek Python, Java and C++. So refer the below section for code −
Using Python
The custom encryption in this implementation is based on shifting the ASCII value of each character in the concatenated key. For even-indexed characters, each is shifted by the length of public key, and for odd-indexed characters, each is shifted by the length of symmetric key. This is a simple type of encryption that still uses the method combining keys and applying customized transformations. So see the Python implementation below −
def hybrid_encrypt(message, public_key, symmetric_key): # Reverse the message reversed_message = message[::-1] # Combine reversed message with symmetric key combined_key = reversed_message + symmetric_key # change combined key to list of characters key_characters = list(combined_key) # Apply custom encryption encrypted_characters = [] for i, char in enumerate(key_characters): if i % 2 == 0: encrypted_char = chr(ord(char) + len(public_key)) # Shift ASCII value by length of public key else: encrypted_char = chr(ord(char) - len(symmetric_key)) # Shift ASCII value by length of symmetric key encrypted_characters.append(encrypted_char) # Combine encrypted characters encrypted_message = ''.join(encrypted_characters) return encrypted_message # our message, public key and symmetric key message = "hellotutorialspoint" public_key = "qwer" symmetric_key = "private" # function execution encrypted_message = hybrid_encrypt(message, public_key, symmetric_key) print("Our Encrypted Message:", encrypted_message)
Output
Our Encrypted Message: xgmhtlpZmksmymsep^livbzZx^
Using Java
This Java program demonstrates a hybrid encryption technique applied to a plaintext message using a given key. The main method initializes a plaintext message and a key, then calls the encryptMessage function to encrypt the plaintext.
import java.util.*; class HybridEncryption { public static void main(String[] args) { String plaintext = "hellotutorialspoint"; String key = "qwer"; System.out.println("Our Encrypted Message is: " + encryptMessage(plaintext, key)); } public static String encryptMessage(String message, String key) { int a = 0, b = 1, c = 0, m = 0, k = 0, j = 0; String encryptedText = "", temp = ""; // Reverse the message StringBuilder reversedMessage = new StringBuilder(message).reverse(); // Combine the reversed message with the key StringBuilder combinedString = reversedMessage.append(key); // change the combined string to a character array char[] charArray = combinedString.toString().toCharArray(); String evenChars = "", oddChars = ""; // Separate characters into even and odd positions for (int i = 0; i < charArray.length; i++) { if (i % 2 == 0) { oddChars += charArray[i]; }else { evenChars += charArray[i]; } } char[] evenArray = new char[evenChars.length()]; char[] oddArray = new char[oddChars.length()]; // create a Fibonacci series and apply Caesar cipher while (m <= key.length()) { if (m == 0) m = 1; else { a = b; b = c; c = a + b; for (int i = 0; i < evenChars.length(); i++) { int p = evenChars.charAt(i); int cipher = 0; if (Character.isDigit(p)) { cipher = p - c; if (cipher < '0') cipher = cipher + 9; }else { cipher = p - c; if (cipher < 'a') { cipher = cipher + 26; } } evenArray[i] = (char)cipher; } for (int i = 0; i < oddChars.length(); i++) { int p = oddChars.charAt(i); int cipher = 0; if (Character.isDigit(p)) { cipher = p + c; if (cipher > '9') cipher = cipher - 9; }else { cipher = p + c; if (cipher > 'z') { cipher = cipher - 26; } } oddArray[i] = (char)cipher; } m++; } } // Combine even and odd characters based on their positions for (int i = 0; i < charArray.length; i++) { if (i % 2 == 0) { charArray[i] = oddArray[k]; k++; }else { charArray[i] = evenArray[j]; j++; } } // Generate the encrypted text for (char d : charArray) { encryptedText = encryptedText + d; } // Return the encrypted text return encryptedText; } }
Output
Our Encrypted Message is: wkllspoxlorqxqriobknzbu
Using C++
This C++ code shows a custom encryption algorithm that combines reverse string manipulation with a Caesar cipher to encrypt a message.
#include <iostream> #include <string> #include <algorithm> // Include the algorithm header for the reverse function using namespace std; string hybridEncryption(string password, string key) { int a = 0, b = 1, c = 0, m = 0, k = 0, j = 0; string cipherText = "", temp = ""; // Declare a password string string reversedPassword = password; // Reverse the String reverse(reversedPassword.begin(), reversedPassword.end()); // Use the reverse function reversedPassword = reversedPassword + key; // For future Purpose temp = reversedPassword; string charArray = temp; string evenChars = "", oddChars = ""; // Declare EvenArray for storing // even index of charArray char *evenArray; // Declare OddArray for storing // odd index of charArray char *oddArray; // Storing the positions in their // respective arrays for (int i = 0; i < charArray.length(); i++) { if (i % 2 == 0) { oddChars = oddChars + charArray[i]; }else { evenChars = evenChars + charArray[i]; } } evenArray = new char[evenChars.length()]; oddArray = new char[oddChars.length()]; // Generate a Fibonacci Series // Upto the Key Length while (m <= key.length()) { // As it always starts with 1 if (m == 0) m = 1; else { // Logic For Fibonacci Series a = b; b = c; c = a + b; for (int i = 0; i < charArray.length(); i++) { // Caesar Cipher Algorithm Start // for even positions int p = charArray[i]; int cipher = 0; if (p == '0' || p == '1' || p == '2' || p == '3' || p == '4' || p == '5' || p == '6' || p == '7' || p == '8' || p == '9') { cipher = p - c; if (cipher < '0') cipher = cipher + 9; }else { cipher = p - c; if (cipher < 'a') { cipher = cipher + 26; } } evenArray[i] = (char)cipher; // Caesar Cipher Algorithm End } for (int i = 0; i < charArray.length(); i++) { // Caesar Cipher Algorithm // Start for odd positions int p = charArray[i]; int cipher = 0; if (p == '0' || p == '1' || p == '2' || p == '3' || p == '4' || p == '5' || p == '6' || p == '7' || p == '8' || p == '9') { cipher = p + c; if (cipher > '9') cipher = cipher - 9; }else { cipher = p + c; if (cipher > 'z') { cipher = cipher - 26; } } oddArray[i] = (char)cipher; // Caesar Cipher Algorithm End } m++; } } // Storing content of even and // odd array to the string array for (int i = 0; i < charArray.length(); i++) { if (i % 2 == 0) { charArray[i] = oddArray[k]; k++; }else { charArray[i] = evenArray[j]; j++; } } // Generating a Cipher Text // by charArray (Caesar Cipher) for (char d : charArray) { cipherText = cipherText + d; } // Return the Cipher Text return cipherText; } // Driver code int main() { string pass = "hellotutorialspoint"; string key = "qwer"; cout <<"Our Encrypted Message is: "<< hybridEncryption(pass, key); return 0; }
Output
Our Encrypted Message is: wqqklfrlsmvpoidxlfuorlw
Advantages of Hybrid Cryptography
Hybrid encryption is a combination of symmetric and asymmetric encryption, and it provides higher security than previous methods.The transmission of data becomes secure. Encrypting data during transmission gives security benefits exactly like how data security is ensured on all devices.