#!/usr/local/bin/ruby # # Copyright (c) 2000-2002,2021 M.T. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the author nor the names of its contributors may # be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # beginning = 0 row_size = 16 column_size = 16 class Hexnum < Object def initialize(num = 0) @num = num end def to_hex(rank = nil) char = "" while (@num >= 16) do value = @num % 16 char = char_to_hex(value) + char @num = @num / 16 end char = char_to_hex(@num) + char if (!rank) then return char else for i in 1..rank do char = "0" + char end return char[char.size - rank, rank] end end def Hexnum::to_hex(num, rank = nil) Hexnum.new(num).to_hex(rank) end private def char_to_hex(value) if (value > 9) then value = (value + 'A'.unpack("C")[0] - 10).chr else value = value.to_s end return value end end matrix = Array.new(column_size) for i in 0..(column_size - 1) do matrix[i] = Array.new(row_size) end continue = true blocks = 0 while (continue) do sum_of_column = Array.new(row_size, 0) for i in 0..(column_size - 1) do print Hexnum::to_hex(blocks * column_size * row_size + i * row_size + beginning, 4) + " " sum_of_row = 0 for j in (0..row_size - 1) do if (continue) then char = $<.getbyte if (char) then matrix[i][j] = char sum_of_row += char sum_of_column[j] += char else matrix[i][j] = 0 continue = false end else matrix[i][j] = 0 end print Hexnum::to_hex(matrix[i][j], 2) + " " if (j == 7) then print " " end end print " " + Hexnum::to_hex(sum_of_row, 2) + " " for j in (0..row_size - 1) do if (matrix[i][j] >= 0x20 && matrix[i][j] < 0x7f) || \ (matrix[i][j] >= 0xa0 && matrix[i][j] < 0xb0) print matrix[i][j].chr else print "." end end print "\n" end print "\n " sum_of_row = 0 for j in (0..row_size - 1) do sum_of_row += sum_of_column[j] print Hexnum::to_hex(sum_of_column[j], 2) + " " if (j == 7) then print " " end end print " " + Hexnum::to_hex(sum_of_row, 2) + "\n\n\n" blocks += 1 end