The DNA-based cryptography is a new and very promising direction in cryptography research, DNA can be used in cryptography for storing and transmitting the
information.
Each character of the text will be converted to 8-bit binary. But the lenght of the text must be multiple by 3, Because it will be converted to DNA Bases and next to DNA Codons. This part of code will check that, and add character 'X' to fill the void:
while((msg.length() % 3) != 0) {
msg += "X";
}
E.g. "Hi" will be "HiX" then will be 01001000 01101001 01011000
In this step, every couple of two bit will be converted to the one of the DNA Bases(A, C, G, T).
- 00 will be base A.
- 01 will be the base C.
- 10 will be the base G.
- 11 will be the base T.
E.g. 01001000 01101001 01011000 will be "CAGACGGCCCGA"
Every DNA Codons will be one of the Amio Acids in the following table with their index. Amino Acids table wil be implemented asHashMap<String, ArrayList<String>>
.
for (String key : AminoAcidTable.keySet()) {
for(int j = 0; j < AminoAcidTable.get(key).size(); j++) {
if(AminoAcidTable.get(key).get(j).equals(dnaCodons))
aminoacidMsg += key + (char) (j + 'A');
}
}
The STOP Codons will be converted to character 'Z'.
E.g. "CAGACGGCCCGA" will be "QBTDABRC" (Q1T3A1R2)
Vigenere Cipher is a method of encrypting alphabetic text. It uses a simple form of polyalphabetic substitution. The easy implementation could be to visualize Vigenere algebraically by converting [A-Z] into numbers [0–25].
Ei = (Pi + Ki) mod 26
The plaintext(P) and key(K) This part of code implements the equation:
for(int i = 0; i < msg.length(); i++)
encryptedMsg += (char) (((msg.charAt(i) + key.charAt(i % key.length())) % 26) + 'A');
E.g. Encryption of "QBTDABRC" with the key "pizza" will be "FJSCAQZB"
So "Hi" will be encrypted to "FJSCAQZB"
The equation bellow explain how to decrypt from ciphertext to plantext using Vigenere Cipher.
Ei = (Pi - Ki + 26) mod 26
The plaintext(P) and key(K)
Now it's easy to get the DNA Codos simply by callingAminoAcidTable.get(Key)
, it will return anArrayList<String>
, then we can easly find the DNA Codon using the index after converting them from letter to number('A' will be 0, 'B' wil be 1....) .
This part of code implements that:
for(int i = 0; i < msg.length(); i += 2) {
dnaMsg += AminoAcidTable.get(msg.substring(i, i+1)).get((int) (msg.charAt(i+1) - 'A'));
}
Each DNA Base will be converted to their binary code as follows:
- The base A will be 00.
- The base C will be 01.
- The base G will be 10.
- The base T will be 11.
The final step is to converting every 8-bit to character.