class CommonEnc

Constants

CSTR_DICT
HEX_DICT

Public Class Methods

decrypt(instr) click to toggle source
# File lib/common_enc.rb, line 59
def self.decrypt(instr)
  mid = []
  (instr.length/2).times do |i|
    v = (instr[i*2].to_i(16) << 4) | instr[i*2+1].to_i(16)
    mid << ( v^CSTR_DICT[i%CSTR_DICT.length] )
  end
  mid.pack("c"*mid.length)
end
get_instance() click to toggle source
# File lib/common_enc.rb, line 68
def self.get_instance
  @@single_instance
end
new(files) click to toggle source
# File lib/common_enc.rb, line 13
def initialize(files)
  @files = files
  @@single_instance = self
end

Public Instance Methods

_(str) click to toggle source

function used in erb file

# File lib/common_enc.rb, line 77
def _(str)
  id = add(str_to_id(str), str)
  return "#{getstr_funcname}(#{id})"
end
add(id, str) click to toggle source

add an new item id<->str

# File lib/common_enc.rb, line 35
def add(id, str)
  @dict = Hash.new if @dict.nil?
  newid = id
  if @dict.has_key? id
    if @dict[id] != str
      newid = (id.to_s + "_1").intern
      return add newid, str
    end
    return id
  end
  
  @dict[id] = str
  return id
end
dict() click to toggle source

for debug

# File lib/common_enc.rb, line 51
def dict
  @dict
end
encrypt(instr) click to toggle source
# File lib/common_enc.rb, line 18
def encrypt(instr)
  rst = ""
  idx = 0
  instr.each_byte do |b| 
    v = CSTR_DICT[idx%CSTR_DICT.length]^b
    rst += HEX_DICT[v>>4]
    rst += HEX_DICT[v&0xf]
    idx += 1 
  end
  return rst
end
files() click to toggle source
# File lib/common_enc.rb, line 55
def files
  @files
end
gem_root_dir() click to toggle source
# File lib/common_enc.rb, line 9
def gem_root_dir
  File.absolute_path(File.join(File.dirname(File.expand_path(__FILE__)), ".."))
end
getstr_funcname() click to toggle source
# File lib/common_enc.rb, line 72
def getstr_funcname
  "_"
end
str_to_id(str) click to toggle source
# File lib/common_enc.rb, line 30
def str_to_id(str) 
  Digest::SHA256.bubblebabble(Digest::SHA256.digest(str)).upcase.gsub('-','_').intern
end