Ah, I finally understand! You should have made this way clearer in your original post. He's using the numbers after each a,t,g, or c to indicate which letter it is.
So for example, because t spans g through l (according to his key), typing t5 would lead to:
g, h, i, j, k,
l. I didn't translate his whole example encrypted String but I know it starts out with "I, michael".
So now I can comment on it. Cryptographically, it sucks. But you knew that, saying you didn't care about security, and just wanted to see how to write an algorithm to decode it. So I'm going to do that, because I'm nice and I'm bored. I code in java.
- Code: Select all
import java.util.Scanner;
public class DNAencryption {
public static void main(String[] args) {
String code = "";
String cleartext = "";
String[] a = {"a","b","c","d","e","f",};
String[] t = {"g","h","i","j","k","l",};
String[] g = {"m","n","o","p","q","r",};
String[] c = {"s","t","u","v","w","x","y","z"};
Scanner input = new Scanner(System.in);
System.out.println("Input a string to decrypt.");
code = input.nextLine();
for(int i=0; i<code.length();) {
if(code.charAt(i)=='a') {
cleartext += a[Character.getNumericValue(code.charAt(i+1))-1];
i+=2;
}
else if(code.charAt(i)=='t') {
cleartext += t[Character.getNumericValue(code.charAt(i+1))-1];
i+=2;
}
else if(code.charAt(i)=='g') {
cleartext += g[Character.getNumericValue(code.charAt(i+1))-1];
i+=2;
}
else if(code.charAt(i)=='c') {
cleartext += c[Character.getNumericValue(code.charAt(i+1))-1];
i+=2;
}
else {
cleartext += code.charAt(i);
i++;
}
}
System.out.println(cleartext);
}
}
There's definitely a more elegant solution than creating arrays for a, t, g, and c at the top (like incrementing ASCII values or something), but this will decrypt it. Also note there are two errors in the sample you posted: the second to last character "f" should be "g", and the first character of the third word should be "g", not "t". When those are fixed the sample code given will output: "i, michael waod, need help". I'll explain the code in another post sometime soon if you want.