Saltar al contenido
Underc0de /foro

Convertidor de string a binario y viceversa

Iniciado por B3N, Junio 20, 2015, 10:33:08 PM

Tema anterior - Siguiente tema

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

Avatar de B3N
Junio 20, 2015, 10:33:08 PM Ultima modificación: Junio 25, 2015, 10:36:12 PM por B3N
Pueden sugerir arreglos. Espero les sea de utilidad.

Código: ruby
# 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
WhatsApp Telegram
01010111 01100001 01101011 01100101 00100000 01110101
01110000 00100000 01001110 01100101 01101111

¿Te quedó una duda sobre Ruby?

Preguntala y te responde la comunidad (y el asistente Underc0de IA si nadie llega antes). Es gratis y tarda un minuto.

Ya tengo cuenta
Guardamos tu pregunta en este navegador: después de entrar la publicás con un clic.
Grupo de WhatsApp