code: function padded_string(str)
  {
     if (str.length == 0)
         return '';
   
     var pad = padded_length(str.length) - str.length;
     var res = str;
     for (var i=0; i < pad; ++i)
         res += String.fromCharCode(0);
  
     return res;
  }
docs: TODO: make it return buffer? str += is slow