DNA Cryptography (original) (raw)

Last Updated : 11 Jul, 2025

Cryptography is the branch of science that deals with the **encoding of information to hide messages. It plays a vital role in the infrastructure of communication security. The Pioneering work had been done by Ashish Gehani et al and Amin et al after Leonard Max Adleman had shown the capability of molecular computation in 1994. This paved the way for DNA Computing. DNA Cryptology combines cryptology and modern biotechnology.

**Why DNA Cryptography?

**DNA Cryptography can be defined as hiding data in terms of DNA Sequence. Just like the RSA and DES algorithms, in DNA Cryptology users have DNA algorithms like “Public-key system using DNA as a one-way function for key distribution,” “DNASC cryptography system”, DNA Steganography Systems, Triple stage DNA Cryptography, Encryption algorithm inspired by DNA and Chaotic computing.

So, how do encode data in a DNA strand which is mainly made, up of 4 nitrogenous bases namely:

  1. Adenine (A)
  2. Thymine (T)
  3. Cytosine (C)
  4. Guanine (G)

**The easiest way to encode is to represent these four units as four figures:

A(0) –00
T(1) –01
C(2)–10
G(3)–11

So now converted our initial number into a sequence of A, T, G, and C theoretically. This is then physically implemented using various DNA synthesizing techniques like Chemical Oligonucleotide Synthesis and Oligo Synthesis Platforms (this includes column-based Oligo Synthesis, Array-based Oligo Synthesis, Complex Strand and Gene Synthesis and Error Correction).
Let’s take an example of the classic XOR One Time Pad and see how its implemented using DNA Cryptography:
**Example - Let M be the message and K be the key. The Ciphertext is obtained by finding M xor K = C. User can again obtain the Encoded message by doing: C xor K = M xor K xor K= M. Hence, get our original message. The steps involved in implementing it is:

  1. The message and the OTP key are converted to ASCII bits
  2. Zero Padding is added to the message and the key in order to make the size of their binary codes even
  3. The message and the key are XORed together
  4. The XOR output is represented in DNA bases format. This is our enciphered text.

**The decryption process involves the following processes and hence it is also prone to eavesdropping:

  1. All the DNA bases are transformed into bits.
  2. These bits are then XORed with the OTP key bits to reproduce the original plain text.
  3. This text so obtained in binary format is then converted into a sequence of ASCII characters.

Similarly, users can implement other crypto algorithms like AES and even DES. Instead of storing data as a sequence of 0s and 1s, storing them as a sequence of nitrogenous bases. Storing information in the form of DNA enables us to store a lot of data in a small area.

**Here's an example of DNA cryptography that demonstrates the encoding and decoding of a message using a simple substitution cipher:

C++ `

#include <bits/stdc++.h> using namespace std;

// Define the corrected DNA encoding and // decoding dictionaries with unique mappings unordered_map<char, string> encodingDict = { {'A', "AAA"}, {'B', "AAC"}, {'C', "AAG"}, {'D', "AAT"}, {'E', "ACA"}, {'F', "ACC"}, {'G', "ACG"}, {'H', "ACT"}, {'I', "AGA"}, {'J', "AGC"}, {'K', "AGG"}, {'L', "AGT"}, {'M', "ATA"}, {'N', "ATC"}, {'O', "ATG"}, {'P', "ATT"}, {'Q', "CAA"}, {'R', "CAC"}, {'S', "CAG"}, {'T', "CAT"}, {'U', "CCA"}, {'V', "CCC"}, {'W', "CCG"}, {'X', "CCT"}, {'Y', "CGA"}, {'Z', "CGC"}, {' ', "CGG"} };

unordered_map<string, char> decodingDict;

// Function to initialize decoding dictionary void initializeDecodingDict() { for (auto& pair : encodingDict) { decodingDict[pair.second] = pair.first; } }

// Function to encrypt a message using DNA encoding string encrypt(string message) { string encrypted = ""; for (char c : message) { if (encodingDict.find(c) != encodingDict.end()) { encrypted += encodingDict[c]; } else {

        // If character is not in encodingDict
        // Placeholder for unknown characters
        encrypted += "XXX";
    }
}
return encrypted;

}

// Function to decrypt a DNA-encoded message string decrypt(string encrypted) { string decrypted = "";

// Read in chunks of 3
for (size_t i = 0; i < encrypted.length(); i += 3) {
    string triplet = encrypted.substr(i, 3);
    if (decodingDict.find(triplet) != decodingDict.end()) {
        decrypted += decodingDict[triplet];
    } else {
        // Placeholder for unknown sequences
        decrypted += "?";
    }
}
return decrypted;

}

int main() { initializeDecodingDict(); // Initialize decoding dictionary

string message = "HELLO WORLD";
cout << "Original Message: " << message << endl;

// Encryption
string encryptedMessage = encrypt(message);
cout << "Encrypted Message: " << encryptedMessage << endl;

// Decryption
string decryptedMessage = decrypt(encryptedMessage);
cout << "Decrypted Message: " << decryptedMessage << endl;

return 0;

}

Java

import java.util.HashMap; import java.util.Map;

class GfG {

// Define the corrected DNA encoding and 
// decoding dictionaries with unique mappings
static Map<Character, String> encodingDict = new HashMap<>();
static Map<String, Character> decodingDict = new HashMap<>();

static {
    encodingDict.put('A', "AAA"); encodingDict.put('B', "AAC"); encodingDict.put('C', "AAG"); encodingDict.put('D', "AAT");
    encodingDict.put('E', "ACA"); encodingDict.put('F', "ACC"); encodingDict.put('G', "ACG"); encodingDict.put('H', "ACT");
    encodingDict.put('I', "AGA"); encodingDict.put('J', "AGC"); encodingDict.put('K', "AGG"); encodingDict.put('L', "AGT");
    encodingDict.put('M', "ATA"); encodingDict.put('N', "ATC"); encodingDict.put('O', "ATG"); encodingDict.put('P', "ATT");
    encodingDict.put('Q', "CAA"); encodingDict.put('R', "CAC"); encodingDict.put('S', "CAG"); encodingDict.put('T', "CAT");
    encodingDict.put('U', "CCA"); encodingDict.put('V', "CCC"); encodingDict.put('W', "CCG"); encodingDict.put('X', "CCT");
    encodingDict.put('Y', "CGA"); encodingDict.put('Z', "CGC"); encodingDict.put(' ', "CGG");

    for (Map.Entry<Character, String> entry : encodingDict.entrySet()) {
        decodingDict.put(entry.getValue(), entry.getKey());
    }
}

// Function to encrypt a message using DNA encoding
static String encrypt(String message) {
    String encrypted = "";
    for (char c : message.toCharArray()) {
        if (encodingDict.containsKey(c)) {
            encrypted += encodingDict.get(c);
        } else {
            // If character is not in encodingDict
            // Placeholder for unknown characters
            encrypted += "XXX";
        }
    }
    return encrypted;
}

// Function to decrypt a DNA-encoded message
static String decrypt(String encrypted) {
    String decrypted = "";

    // Read in chunks of 3
    for (int i = 0; i < encrypted.length(); i += 3) {
        String triplet = encrypted.substring(i, Math.min(i + 3, encrypted.length()));
        if (decodingDict.containsKey(triplet)) {
            decrypted += decodingDict.get(triplet);
        } else {
            // Placeholder for unknown sequences
            decrypted += "?";
        }
    }
    return decrypted;
}

public static void main(String[] args) {
    String message = "HELLO WORLD";
    System.out.println("Original Message: " + message);

    // Encryption
    String encryptedMessage = encrypt(message);
    System.out.println("Encrypted Message: " + encryptedMessage);

    // Decryption
    String decryptedMessage = decrypt(encryptedMessage);
    System.out.println("Decrypted Message: " + decryptedMessage);
}

}

Python

Define the corrected DNA encoding and

decoding dictionaries with unique mappings

encodingDict = { 'A': 'AAA', 'B': 'AAC', 'C': 'AAG', 'D': 'AAT', 'E': 'ACA', 'F': 'ACC', 'G': 'ACG', 'H': 'ACT', 'I': 'AGA', 'J': 'AGC', 'K': 'AGG', 'L': 'AGT', 'M': 'ATA', 'N': 'ATC', 'O': 'ATG', 'P': 'ATT', 'Q': 'CAA', 'R': 'CAC', 'S': 'CAG', 'T': 'CAT', 'U': 'CCA', 'V': 'CCC', 'W': 'CCG', 'X': 'CCT', 'Y': 'CGA', 'Z': 'CGC', ' ': 'CGG' }

decodingDict = {v: k for k, v in encodingDict.items()}

Function to encrypt a message using DNA encoding

def encrypt(message): encrypted = '' for char in message: if char in encodingDict: encrypted += encodingDict[char] else: # If character is not in encodingDict # Placeholder for unknown characters encrypted += 'XXX'
return encrypted

Function to decrypt a DNA-encoded message

def decrypt(encrypted): decrypted = ''

# Read in chunks of 3
for i in range(0, len(encrypted), 3):  
    triplet = encrypted[i:i+3]
    if triplet in decodingDict:
        decrypted += decodingDict[triplet]
    else:
        # Placeholder for unknown sequences
        decrypted += '?'  
return decrypted

if name == "main": message = "HELLO WORLD" print("Original Message:", message)

# Encryption
encryptedMessage = encrypt(message)
print("Encrypted Message:", encryptedMessage)

# Decryption
decryptedMessage = decrypt(encryptedMessage)
print("Decrypted Message:", decryptedMessage)

C#

using System; using System.Collections.Generic;

class GfG {

// Define the corrected DNA encoding and 
// decoding dictionaries with unique mappings
static Dictionary<char, string> encodingDict = new Dictionary<char, string> {
    {'A', "AAA"}, {'B', "AAC"}, {'C', "AAG"}, {'D', "AAT"},
    {'E', "ACA"}, {'F', "ACC"}, {'G', "ACG"}, {'H', "ACT"},
    {'I', "AGA"}, {'J', "AGC"}, {'K', "AGG"}, {'L', "AGT"},
    {'M', "ATA"}, {'N', "ATC"}, {'O', "ATG"}, {'P', "ATT"},
    {'Q', "CAA"}, {'R', "CAC"}, {'S', "CAG"}, {'T', "CAT"},
    {'U', "CCA"}, {'V', "CCC"}, {'W', "CCG"}, {'X', "CCT"},
    {'Y', "CGA"}, {'Z', "CGC"}, {' ', "CGG"}
};

static Dictionary<string, char> decodingDict = new Dictionary<string, char>();

static GfG() {
    foreach (var pair in encodingDict) {
        decodingDict[pair.Value] = pair.Key;
    }
}

// Function to encrypt a message using DNA encoding
static string Encrypt(string message) {
    string encrypted = "";
    foreach (char c in message) {
        if (encodingDict.ContainsKey(c)) {
            encrypted += encodingDict[c];
        } else {
            // If character is not in encodingDict
            // Placeholder for unknown characters
            encrypted += "XXX";
        }
    }
    return encrypted;
}

// Function to decrypt a DNA-encoded message
static string Decrypt(string encrypted) {
    string decrypted = "";

    // Read in chunks of 3
    for (int i = 0; i < encrypted.Length; i += 3) {
        string triplet = encrypted.Substring(i, Math.Min(3, encrypted.Length - i));
        if (decodingDict.ContainsKey(triplet)) {
            decrypted += decodingDict[triplet];
        } else {
            // Placeholder for unknown sequences
            decrypted += "?";
        }
    }
    return decrypted;
}

static void Main() {
    string message = "HELLO WORLD";
    Console.WriteLine("Original Message: " + message);

    // Encryption
    string encryptedMessage = Encrypt(message);
    Console.WriteLine("Encrypted Message: " + encryptedMessage);

    // Decryption
    string decryptedMessage = Decrypt(encryptedMessage);
    Console.WriteLine("Decrypted Message: " + decryptedMessage);
}

}

JavaScript

// Define the corrected DNA encoding and // decoding dictionaries with unique mappings const encodingDict = { A: "AAA", B: "AAC", C: "AAG", D: "AAT", E: "ACA", F: "ACC", G: "ACG", H: "ACT", I: "AGA", J: "AGC", K: "AGG", L: "AGT", M: "ATA", N: "ATC", O: "ATG", P: "ATT", Q: "CAA", R: "CAC", S: "CAG", T: "CAT", U: "CCA", V: "CCC", W: "CCG", X: "CCT", Y: "CGA", Z: "CGC", " ": "CGG" };

// Create the decoding dictionary const decodingDict = Object.fromEntries( Object.entries(encodingDict).map(([k, v]) => [v, k]) );

// Function to encrypt a message using DNA encoding function encrypt(message) { let encrypted = ""; for (let char of message) { if (encodingDict[char]) { encrypted += encodingDict[char]; } else { // If character is not in encodingDict // Placeholder for unknown characters encrypted += "XXX"; } } return encrypted; }

// Function to decrypt a DNA-encoded message function decrypt(encrypted) { let decrypted = "";

// Read in chunks of 3
for (let i = 0; i < encrypted.length; i += 3) {
    let triplet = encrypted.substring(i, i + 3);
    if (decodingDict[triplet]) {
        decrypted += decodingDict[triplet];
    } else {
        // Placeholder for unknown sequences
        decrypted += "?";
    }
}
return decrypted;

}

// Driver Code const message = "HELLO WORLD"; console.log("Original Message:", message);

// Encryption const encryptedMessage = encrypt(message); console.log("Encrypted Message:", encryptedMessage);

// Decryption const decryptedMessage = decrypt(encryptedMessage); console.log("Decrypted Message:", decryptedMessage);

`

Output

Original Message: HELLO WORLD Encrypted Message: ACTACAAGTAGTATGCGGCCGATGCACAGTAAT Decrypted Message: HELLO WORLD

In this example, the encoding_dict and decoding_dict dictionaries represent the mapping between DNA bases and their corresponding letters (A, T, C, G). The 'encrypt' function takes a message as input and converts each letter to its corresponding DNA base pairs according to the encoding_dict. The 'decrypt' function takes the DNA-encoded message and converts each DNA base pair back to the original letter using the decoding_dict.

This demonstrates the basic idea of DNA cryptography, where the original message is encrypted using DNA encoding (mapping letters to DNA base pairs) and then decrypted back to the original message by reversing the process.

Advantages

Disadvantages

Conclusion

DNA cryptography is a novel topic that offers strict levels of security and storage capacity by mixing cryptographic methods with biological processes. Although its cost and complexity limits, its promise in areas like as data storage and secure communication is encouraging. DNA cryptography may become increasingly common and accessible as technology advances.