mirror of
https://github.com/cliffe/SecGen.git
synced 2026-02-21 11:18:06 +00:00
encoders/cipher/braille: local files parameters and outputs are enforced utf-8.
This commit is contained in:
@@ -40,6 +40,7 @@ class StringEncoder
|
||||
|
||||
def read_arguments
|
||||
# Get command line arguments
|
||||
Print.local 'Reading args from STDIN'
|
||||
if ARGV.size == 0
|
||||
begin
|
||||
args_array = []
|
||||
@@ -115,6 +116,7 @@ class StringEncoder
|
||||
Print.local module_name
|
||||
|
||||
read_arguments
|
||||
enforce_utf8(self.strings_to_encode)
|
||||
|
||||
Print.local_verbose "Encoding '#{encoding_print_string}'"
|
||||
encode_all
|
||||
@@ -129,6 +131,15 @@ class StringEncoder
|
||||
Print.local_verbose "(Displaying 1000/#{length} length output)"
|
||||
end
|
||||
|
||||
enforce_utf8(self.outputs)
|
||||
print_outputs
|
||||
end
|
||||
|
||||
def enforce_utf8(values)
|
||||
values.map { |o| o.force_encoding('UTF-8') }
|
||||
end
|
||||
|
||||
def print_outputs
|
||||
puts has_base64_inputs ? base64_encode_outputs : self.outputs
|
||||
end
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ class StringGenerator
|
||||
|
||||
def read_arguments
|
||||
# Get command line arguments
|
||||
Print.local 'Reading args from STDIN'
|
||||
if ARGV.size == 0
|
||||
begin
|
||||
args_array = []
|
||||
@@ -112,10 +113,16 @@ class StringGenerator
|
||||
Print.local_verbose "(Displaying 1000/#{length} length output)"
|
||||
end
|
||||
|
||||
enforce_utf8(self.outputs)
|
||||
print_outputs
|
||||
end
|
||||
|
||||
def enforce_utf8(values)
|
||||
values.map { |o| o.force_encoding('UTF-8') }
|
||||
end
|
||||
|
||||
def print_outputs
|
||||
puts has_base64_inputs ? base64_encode_outputs : self.outputs
|
||||
|
||||
# TODO: Wrap data in {}
|
||||
|
||||
end
|
||||
|
||||
def base64_encode_outputs
|
||||
|
||||
@@ -319,8 +319,6 @@ class System
|
||||
end
|
||||
# execute calculation script and format output to an array of Base64 strings
|
||||
Print.verbose "Running: ruby #{selected.local_calc_file} #{args_string[0..200]} ..."
|
||||
$stdout.sync = true
|
||||
$stderr.sync = true
|
||||
stdout, stderr, status = Open3.capture3("ruby #{selected.local_calc_file}", :stdin_data => args_string)
|
||||
puts stderr
|
||||
outputs = stdout.chomp
|
||||
|
||||
0
modules/encoders/cipher/braille/braille.pp
Normal file
0
modules/encoders/cipher/braille/braille.pp
Normal file
28
modules/encoders/cipher/braille/secgen_local/local.rb
Normal file
28
modules/encoders/cipher/braille/secgen_local/local.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/ruby
|
||||
require_relative '../../../../../lib/objects/local_string_encoder.rb'
|
||||
require 'braille'
|
||||
require 'braille/translator'
|
||||
|
||||
class BrailleEncoder < StringEncoder
|
||||
|
||||
def initialize
|
||||
super
|
||||
self.module_name = 'Braille Encoder'
|
||||
self.strings_to_encode = []
|
||||
end
|
||||
|
||||
def encode(str)
|
||||
braille = Braille::Translator.new
|
||||
translation = []
|
||||
str.each_char do |char|
|
||||
if ! char =~ /[a-zA-Z0-9]/ # If non-alphanumeric, return the character as is.
|
||||
translation << char
|
||||
else
|
||||
translation << braille.translate_word(char)
|
||||
end
|
||||
end
|
||||
translation.join
|
||||
end
|
||||
end
|
||||
|
||||
BrailleEncoder.new.run
|
||||
28
modules/encoders/cipher/braille/secgen_metadata.xml
Normal file
28
modules/encoders/cipher/braille/secgen_metadata.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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>Braille Code Encoder</name>
|
||||
<author>Thomas Shaw</author>
|
||||
<module_license>MIT</module_license>
|
||||
<description>Encodes a string into Braille.</description>
|
||||
|
||||
<type>braille_encoder</type>
|
||||
<type>ascii_reversible</type>
|
||||
<type>string_encoder</type>
|
||||
<platform>linux</platform>
|
||||
<platform>windows</platform>
|
||||
|
||||
<reference>https://github.com/nicanor/braille</reference>
|
||||
|
||||
<solution>Braille decoders are available online e.g. https://www.dcode.fr/braille-alphabet</solution>
|
||||
|
||||
<read_fact>strings_to_encode</read_fact>
|
||||
|
||||
<default_input into="strings_to_encode">
|
||||
<generator type="flag_generator"/>
|
||||
</default_input>
|
||||
|
||||
<output_type>encoded_strings</output_type>
|
||||
</encoder>
|
||||
Reference in New Issue
Block a user