Created
November 4, 2013 02:35
-
-
Save everblut/7297283 to your computer and use it in GitHub Desktop.
Cifrado por transposicón
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/ruby | |
# *****------->>>>>Usage: cesar.rb 'texto' | |
def transposicion(msg) | |
cif = C(msg).map(&:reverse).transpose.map { |fila| fila.join('') }.join(' ') | |
return "****---->>>> Mensaje cifrado: #{cif} \n****---->>>> Mensaje descifrado: #{C(cif,cif.split[0].size).reverse.transpose.map { |fila| fila.join('') }.join(' ')}" | |
end | |
def C(msg,s=-1) | |
arr,ran, matrix = [msg.split.join.split('')] + [s == -1 ? Random.rand(3...6) : s] + [[[]]] | |
ran.times {|n| arr.each_slice(ran).with_index { |bloq,i| matrix[i] = Array.new(ran).each_with_index.map { |val,idx| val = bloq[idx].nil? ? (10...36).map { |i| i.to_s 36 }.sample : bloq[idx] } } } | |
return matrix | |
end | |
def main | |
return if ARGV[0].nil? | |
puts "\n**-->Mensaje a cifrar [msg]: #{ARGV[0]}\n#{transposicion(ARGV[0].downcase)}" | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment