Module: Rotlib

Defined in:
lib/rotlib.rb

Instance Method Summary collapse

Instance Method Details

#fromHex(data) ⇒ Object



10
11
12
# File 'lib/rotlib.rb', line 10

def fromHex(data)
  return data.split.pack('H*')
end

#rot13(words, iter = 13) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object



7
8
9
# File 'lib/rotlib.rb', line 7

def toHex(data)
  return data.dump.bytes.map {|e| e.to_s(16)}.join
end

#url_decode(url2decode) ⇒ Object



81
82
83
# File 'lib/rotlib.rb', line 81

def url_decode(url2decode)
  return URI::decode_www_form_component(url2decode)
end

#url_encode(url2encode) ⇒ Object



78
79
80
# File 'lib/rotlib.rb', line 78

def url_encode(url2encode)
  return URI.encode_www_form_component(url2encode)
end