pads a string to the right with null-bytes or any other given character.

    ..note:: This is used by the :py:func:`xor` function.

    :param s: the string
    :param N: an integer of how much padding should be done
    :returns: the original bytes
551406
def rpad(s, N, char='\0'):
    
    assert isinstance(char, bytes) and len(char) == 1, 'char should be a string with length 1'
    return s.ljust(N, char)
499589
def null_term(str):
    ''''''
    if sys.version_info.major < 3:
        return str
    if isinstance(str, bytes):
        str = str.decode("utf-8")
    idx = str.find("\0")
    if idx != -1:
        str = str[:idx]
    return str
1228759
public UTF8String rpad(int len, UTF8String pad) {
    int spaces = len - this.numChars(); // number of char need to pad
    if (spaces <= 0 || pad.numBytes() == 0) {
      // no padding at all, return the substring of the current string
      return substring(0, len);
    } else {
      int padChars = pad.numChars();
      int count = spaces / padChars; // how many padding string needed
      // the partial string of the padding
      UTF8String remain = pad.substring(0, spaces - padChars * count);

      byte[] data = new byte[this.numBytes + pad.numBytes * count + remain.numBytes];
      copyMemory(this.base, this.offset, data, BYTE_ARRAY_OFFSET, this.numBytes);
      int offset = this.numBytes;
      int idx = 0;
      while (idx < count) {
        copyMemory(pad.base, pad.offset, data, BYTE_ARRAY_OFFSET + offset, pad.numBytes);
        ++ idx;
        offset += pad.numBytes;
      }
      copyMemory(remain.base, remain.offset, data, BYTE_ARRAY_OFFSET + offset, remain.numBytes);

      return UTF8String.fromBytes(data);
    }
  }
827219
public static function padRight(
        $string,
        $length = 0,
        $substring = ' ',
        $encoding = null
    ) {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        return static::doPad($string, 0, $length - Mbstring::strlen($string, $encoding), $substring, $encoding);
    }
688007
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;
}
729686
function rpad(str, width) {
    str = String(str);
    var n = width - str.length;
    if (n < 1) return str;
    while (n--) str = str + ' ';
    return str;
}
1296756
def to_bytes(x, blocksize=0):
    
    if isinstance(x, bytearray):
        return left_zero_pad(bytes(x), blocksize)
    elif isinstance(x, basestring):
        return left_zero_pad(x, blocksize)
    elif isinstance(x, (list, tuple)):
        return left_zero_pad(bytes(bytearray(x)), blocksize)
    elif isinstance(x, (long, int)):
        return long_to_bytes(x, blocksize)
    else:
        raise ValueError('Unknown input argument type')
1101536
def padStr(s, field=None):
    
    if field is None:
        return s
    else:
      if len(s) >= field:
          return s
      else:
          return " " * (field - len(s)) + s
870248
def removeRandomLenPadding(str, blocksize=AES_blocksize):
  ''
  pad_len = ord(str[-1]) # last byte contains number of padding bytes
  assert pad_len < blocksize, 'padding error' 
  assert pad_len < len(str), 'padding error'
    
  return str[:-pad_len]
734694
public static final Bytes of(String s) {
    Objects.requireNonNull(s);
    if (s.isEmpty()) {
      return EMPTY;
    }
    byte[] data = s.getBytes(StandardCharsets.UTF_8);
    return new Bytes(data, s);
  }
320338
public static String rightPad( String value , int size , char padChar )
    {
        if (value.length() >= size)
            return value;
        
        StringBuilder result = new StringBuilder(size);
        result.append(value);
        for (int n = 0 ; n < size-value.length() ; n++)
            result.append(padChar);        
        return result.toString();
    }
979477
function(str, pad) {
			var padding = '';
			var il = str.length;
				
			while (pad > il++) padding += '0';
			return padding + str; 
		}
1265375
def decode(s):
    
    if isinstance(s, bytes):
        return s.decode(sys.getdefaultencoding())
    else:
        return s
1264917
def removeSpacePadding(str, blocksize=AES_blocksize):
    '' 
    pad_len = 0    
    for char in str[::-1]: # str[::-1] reverses string
        if char == ' ':
            pad_len += 1
        else:
            break

    str = str[:-pad_len]
   
    return str
937888
public String form( String s ) {
        if (fmt != 's') {
            throw new java.lang.IllegalArgumentException();
        }
        if (precision >= 0 && precision < s.length()) {
            s = s.substring(0, precision);
        }

        return pad(s);
    }
166426
def paddingLength(str_len, blocksize=AES_blocksize):
  ''' '''
  assert 0 < blocksize < 255, 'blocksize must be between 0 and 255'
  assert str_len > 0 , 'string length should be non-negative'
  
  'If the last block is already full, append an extra block of padding'
  pad_len = blocksize - (str_len % blocksize)
  
  return pad_len
1182653
def removeZeroLenPadding(str, blocksize=AES_blocksize):
  ''
  try:
    pad_len = ord(str[-1]) # last byte contains number of padding bytes
  except TypeError:
    pad_len = str[-1]
  assert pad_len < blocksize, 'padding error' 
  assert pad_len < len(str), 'padding error'
    
  return str[:-pad_len]