Convertidor de string a binario y viceversa

  • 0 Respuestas
  • 3677 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado B3N

  • *
  • Underc0der
  • Mensajes: 35
  • Actividad:
    0%
  • Reputación 0
  • 00111011 00101001
    • Ver Perfil
    • Email

Convertidor de string a binario y viceversa

  • en: Junio 20, 2015, 10:33:08 pm
Pueden sugerir arreglos. Espero les sea de utilidad.

Código: (ruby) [Seleccionar]
# Copyright (C) 2015 B3N <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Description: String to binary converter and viceversa
# Original name: bconverter.rb
# Version: 1.0

#!/usr/bin/env ruby

def help
puts
puts "Usage: #{__FILE__} -s \"String to convert to binary\""
puts "       #{__FILE__} -b \"00111011 00101001\""
end

if ARGV.empty? || ARGV.length != 2
puts help
elsif ARGV[0] == '-s'
ARGV[1].unpack("C*").each{|c| print "%08b " % c}
print "\n"
elsif ARGV[0] == '-b'
puts [ARGV[1].delete(' ')].pack("B*")
else
puts
puts "[-] incorrect option: #{ARGV[0]}"
help
puts
end
« Última modificación: Junio 25, 2015, 10:36:12 pm por B3N »
01010111 01100001 01101011 01100101 00100000 01110101
01110000 00100000 01001110 01100101 01101111