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|
    if i == len:
     ret << "chr(#{c.to_s})"
     ret << "chr(#{c.to_s})."


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

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

No comments:

Post a Comment