Sunday, February 13, 2011

string to chr() array - ruby style

Hi everyone on my boring blog's readers.(really anybody read my blog? if u read please drop an comment or click my ads :> )
I will only share tiny code snippet that usefull for me. Its converts any string into chr() array, i use it on my php code obfuscator tool. It's here..

def to_chr_array(str)
  ret = ""
  i = 0
  len = str.length

  str.each_byte { |c|
    i+=1
    if i == len:
     ret << "chr(#{c.to_s})"
    else
     ret << "chr(#{c.to_s})."
    end
  }

ret
end


Simple usage:
puts "$variable = #{to_chr_array("hello")};"

Output:
$variable = chr(104).chr(101).chr(108).chr(108).chr(111);

No comments:

Post a Comment