encoders/dna

This commit is contained in:
ts
2018-10-19 12:32:12 +01:00
parent 907fca3f6d
commit 63afa32e14
4 changed files with 97 additions and 0 deletions

View File

View File

@@ -0,0 +1,67 @@
#!/usr/bin/ruby
require_relative '../../../../../lib/objects/local_string_encoder.rb'
class DNACipher < StringEncoder
attr_accessor :char_map
def initialize
super
self.module_name = 'DNA Cipher Encoder'
self.strings_to_encode = []
self.char_map = {
'A' => 'CGA',
'B' => 'CCA',
'C' => 'GTT',
'D' => 'TTG',
'E' => 'GGC',
'F' => 'GGT',
'G' => 'TTT',
'H' => 'CGC',
'I' => 'ATG',
'J' => 'AGT',
'K' => 'AAG',
'L' => 'TGC',
'M' => 'TCC',
'N' => 'TCT',
'O' => 'GGA',
'P' => 'GTG',
'Q' => 'AAC',
'R' => 'TCA',
'S' => 'ACG',
'T' => 'TTC',
'U' => 'CTG',
'V' => 'CCT',
'W' => 'CCG',
'X' => 'CTA',
'Y' => 'AAA',
'Z' => 'CTT',
' ' => 'ATA',
',' => 'TCG',
'.' => 'GAT',
':' => 'GCT',
'0' => 'ACT',
'1' => 'ACC',
'2' => 'TAG',
'3' => 'GCA',
'4' => 'GAG',
'5' => 'AGA',
'6' => 'TTA',
'7' => 'ACA',
'8' => 'AGG',
'9' => 'GCG',
'{' => '{',
'}' => '}',
'_' => '_',
}
end
def encode(str)
encoded = []
str.each_char do |char|
self.char_map.key? char.upcase
encoded << self.char_map[char.upcase]
end
encoded.join
end
end
DNACipher.new.run

View File

@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<encoder xmlns="http://www.github/cliffe/SecGen/encoder"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.github/cliffe/SecGen/encoder">
<name>DNA Cipher</name>
<author>Thomas Shaw</author>
<module_license>MIT</module_license>
<description>
</description>
<type>alpha_reversible</type>
<type>dna_encoder</type>
<type>cipher_encoder</type>
<platform>linux</platform>
<platform>windows</platform>
<reference>http://www.polestarltd.com/ttg/isspeeches/051403/slide14.jpg</reference>
<hint>Guanine, Adenine, Thymine and Cytosine</hint>
<solution>http://www.polestarltd.com/ttg/isspeeches/051403/slide14.jpg</solution>
<read_fact>strings_to_encode</read_fact>
<default_input into="strings_to_encode">
<generator type="flag_generator"/>
</default_input>
<output_type>encoded_string</output_type>
</encoder>