├── Images ├── dna_codes.png └── genome-coding.jpg ├── README.md ├── dna.py └── example_cipher.txt /Images/dna_codes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karma9874/DNA-Cipher-Script-CTF/3167d13d1b3031022384a4ab2ad6381d485eeb61/Images/dna_codes.png -------------------------------------------------------------------------------- /Images/genome-coding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karma9874/DNA-Cipher-Script-CTF/3167d13d1b3031022384a4ab2ad6381d485eeb61/Images/genome-coding.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DNA-Cipher-Script-CTF 2 | A simple script to decode the genome DNA binary sequence (CTF Challenge) 3 | ## Usage 4 | ```python dna.py example_cipher.txt``` 5 | 6 | ## Reference 7 | ![Images/dna_codes.png](Images/dna_codes.png) 8 | ![Images/genome_coding.jpg](Images/genome-coding.jpg) 9 | -------------------------------------------------------------------------------- /dna.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | bin_dna = {'00':'A','10':'C','01':'G','11':'T'} 4 | mapping = { 5 | 'AAA':'a','AAC':'b','AAG':'c','AAT':'d','ACA':'e','ACC':'f', 'ACG':'g','ACT':'h','AGA':'i','AGC':'j','AGG':'k','AGT':'l','ATA':'m','ATC':'n','ATG':'o','ATT':'p','CAA':'q','CAC':'r','CAG':'s','CAT':'t','CCA':'u','CCC':'v','CCG':'w','CCT':'x','CGA':'y','CGC':'z','CGG':'A','CGT':'B','CTA':'C','CTC':'D','CTG':'E','CTT':'F','GAA':'G','GAC':'H','GAG':'I','GAT':'J','GCA':'K','GCC':'L','GCG':'M','GCT':'N','GGA':'O','GGC':'P','GGG':'Q','GGT':'R','GTA':'S','GTC':'T','GTG':'U','GTT':'V','TAA':'W','TAC':'X','TAG':'Y','TAT':'Z','TCA':'1','TCC':'2','TCG':'3','TCT':'4','TGA':'5','TGC':'6','TGG':'7','TGT':'8','TTA':'9','TTC':'0','TTG':' ','TTT':'.'} 6 | 7 | def bin_2_code(string): 8 | string = string.replace(" ","") 9 | string = string.replace("\n","") 10 | final="" 11 | for j in range(0,len(string),2): 12 | final+=bin_dna[string[j:j+2]] 13 | return final 14 | 15 | def decode_dna(string): 16 | final="" 17 | for i in range(0,len(string),3): 18 | final+=mapping[string[i:i+3]] 19 | return final 20 | 21 | if len(sys.argv) < 2: 22 | print("Usage: python dna.py [file_name]") 23 | else: 24 | input_string = open(sys.argv[1]).read().replace(" ","") 25 | print(" ") 26 | print(decode_dna(bin_2_code(input_string))) -------------------------------------------------------------------------------- /example_cipher.txt: -------------------------------------------------------------------------------- 1 | 101110 011011 100101 111101 000100 100001 111101 001000 100001 100001 001000 001110 100011 000100 000000 000111 000111 100100 111101 000000 111101 100010 001000 000001 000100 001111 001000 111101 001010 001101 100010 111101 000000 001110 100100 111101 000111 000100 101010 000100 001110 001001 111101 001101 100010 001001 000000 001110 000100 100001 001100 111111 111101 010001 100011 111101 000001 001101 001110 100011 000000 000100 001110 100001 111101 101010 000100 100011 000000 000111 111101 000100 001110 001010 001101 100010 001100 000000 100011 000100 001101 001110 111101 100011 001011 000000 100011 100001 111101 001111 000000 100001 100001 001000 000011 111101 000011 001101 101001 001110 111101 001010 100010 001101 001100 111101 001101 001110 001000 111101 001001 001000 001110 001000 100010 000000 100011 000100 001101 001110 111101 100011 001101 111101 100011 001011 001000 111101 001110 001000 101011 100011 111111 111101 101110 011011 100101 111101 001100 001101 000111 001000 000001 101000 000111 001000 100001 111101 101001 000100 100011 001011 000100 001110 111101 100011 001011 001000 111101 001110 101000 000001 000111 001000 101000 100001 111101 001101 001010 111101 000000 111101 000001 001000 000111 000111 111101 101001 000100 001110 000011 111101 100011 000100 001001 001011 100011 000111 100100 111101 100011 001101 111101 001010 001101 100010 001100 111101 000001 001011 100010 001101 001100 001101 100001 001101 001100 001000 100001 111101 101001 001011 000100 000001 001011 111101 001011 001000 000111 001111 111101 000101 001000 001000 001111 111101 101110 011011 100101 111101 100001 001000 000001 101000 100010 001000 111101 000000 001110 000011 111101 000100 001110 111101 001111 000111 000000 000001 001000 111101 000000 001110 000011 111101 100001 100011 001101 100010 001000 111101 000100 001100 001111 001101 100010 100011 000000 001110 100011 111101 000100 001110 001010 001101 100010 001100 000000 100011 000100 001101 001110 111101 000100 001110 111101 100011 001011 001000 111101 001010 001101 100010 001100 111101 001101 001010 111101 001001 001000 001110 001000 100001 111101 100011 001101 111101 000011 001000 100011 001000 100010 001100 000100 001110 001000 111101 000000 001110 111101 001101 100010 001001 000000 001110 000100 100001 001100 100001 111101 001001 001000 001110 001000 100011 000100 000001 111101 000100 001110 001010 001101 100010 001100 000000 100011 000100 001101 001110 111111 101111 000111 000000 001001 111101 000100 100001 111101 001110 111110 111110 000010 111101 111011 100010 001100 100100 111101 110110 111110 111000 001110 110110 111101 110101 111110 111101 100010 111110 000001 000101 111101 111110 001110 111001 111101 000011 111011 100100 111111 101110 011011 100101 111101 101001 001101 100010 000101 100001 111101 000010 100100 111101 000001 001101 001111 100100 000100 001110 001001 111101 000100 100011 100001 001000 000111 001010 111101 000100 001110 100011 001101 111101 100011 001011 000000 100011 111101 100001 000100 001110 001001 000111 001000 100001 100011 100010 000000 001110 000011 001000 000011 111101 001100 001101 000111 001000 000001 101000 000111 001000 111101 000001 000000 000111 000111 001000 000011 111101 010111 011011 100101 111111 111101 010001 001010 111101 101110 011011 100101 111101 000100 100001 111101 100011 001011 001000 111101 000010 000111 101000 001000 001111 100010 000100 001110 100011 111101 100100 001101 101000 111101 000001 000000 001110 111101 100011 001011 000100 001110 000101 111101 001101 001010 111101 010111 011011 100101 111101 000000 100001 111101 100011 001011 001000 111101 100011 100010 000000 001110 100001 000111 000000 100011 001101 100010 111101 001101 001010 111101 000100 001110 100001 100011 100010 101000 000001 100011 000100 001101 001110 100001 111101 101001 100010 000100 100011 100011 001000 001110 111101 000100 001110 111101 100011 001011 001000 111101 000010 000111 101000 001000 001111 100010 000100 001110 100011 111111 --------------------------------------------------------------------------------