module Rotlib

Public Instance Methods

fromHex(data) click to toggle source
# File lib/rotlib.rb, line 10
def fromHex(data)
  return data.split.pack('H*')
end
rot13(words, iter = 13) click to toggle source
# File lib/rotlib.rb, line 14
def rot13(words, iter = 13)
  tmp_value = ''
  words.bytes.map do |c|
    if c > 64 and c < 91
      c += iter
      loop do
        if c > 90
          c = (c - 90)+64
        end
        break if c > 64 and c < 91
      end
    elsif c > 96 and c < 123
      c += iter
      loop do
        if c > 122
          c = (c - 122)+96
        end
        break if c > 96 and c < 123
      end
    end
    tmp_value += c.chr
  end
  return tmp_value
end
rot13_log(words, show_max_length = 25) click to toggle source
# File lib/rotlib.rb, line 39
def rot13_log(words, show_max_length = 25)
  if words.length > show_max_length
    words = words.split("\n")[0]
    words = words[0,show_max_length]
  end
  26.times do |i|
    puts "#{i.to_s.rjust 2} \e[32;m>\e[0m #{rot13(words, i)}"
  end
  return
end
rot47(words, iter = 47) click to toggle source
# File lib/rotlib.rb, line 50
def rot47(words,  iter = 47)
  tmp_value = ''
  words.bytes.map do |c|
    if c > 32 and c < 127
      c += iter
      loop do
        if c > 126
          c = (c - 126)+32
        end
        break if c > 32 and c < 127
      end
    end
    tmp_value += c.chr
  end
  return tmp_value
end
rot47_log(words, show_max_length = 25) click to toggle source
# File lib/rotlib.rb, line 67
def rot47_log(words, show_max_length = 25)
  if words.length > show_max_length
    words = words.split("\n")[0]
    words = words[0,show_max_length]
  end
  94.times do |i|
    puts "#{i.to_s.rjust 2} \e[32;m>\e[0m #{rot47(words, i)}"
  end
  return
end
toHex(data) click to toggle source
# File lib/rotlib.rb, line 7
def toHex(data)
  return data.dump.bytes.map {|e| e.to_s(16)}.join
end
url_decode(url2decode) click to toggle source
# File lib/rotlib.rb, line 81
def url_decode(url2decode)
  return URI::decode_www_form_component(url2decode)
end
url_encode(url2encode) click to toggle source
# File lib/rotlib.rb, line 78
def url_encode(url2encode)
  return URI.encode_www_form_component(url2encode)
end