How to use Padding - 10 common examples

To help you get started, we’ve selected a few Padding examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexmgr / pybleach / pkcs1_test_client.py View on Github external
exit(1)
  else:
      print_encrypted = False

  if args.length != None:
    k = NumUtils.pow2_round(args.length)

  if args.hex:
    try:
      cleartexts = [unhexlify(cleartext) for cleartext in cleartexts]
    except TypeError as te:
      print("Cleartext provided is not in hex format: %s: " % cleartext, te, file=stderr)
      parser.print_help()
      exit(1)

  pkcs1 = PKCS1_v15(k)
  for m in cleartexts:
    for i in tests:
      padded_cleartext = getattr(pkcs1, PKCS1_v15.FUNC_TABLE[i])(m)
      if print_encrypted:
        c = rsa.encrypt(padded_cleartext, 0)[0]
        c = "\x00"*(k/8-len(c)) + c
        print(hexlify(c))
      else:
        print(hexlify(padded_cleartext))
github alexmgr / pybleach / pkcs1_test_client.py View on Github external
if args.length != None:
    k = NumUtils.pow2_round(args.length)

  if args.hex:
    try:
      cleartexts = [unhexlify(cleartext) for cleartext in cleartexts]
    except TypeError as te:
      print("Cleartext provided is not in hex format: %s: " % cleartext, te, file=stderr)
      parser.print_help()
      exit(1)

  pkcs1 = PKCS1_v15(k)
  for m in cleartexts:
    for i in tests:
      padded_cleartext = getattr(pkcs1, PKCS1_v15.FUNC_TABLE[i])(m)
      if print_encrypted:
        c = rsa.encrypt(padded_cleartext, 0)[0]
        c = "\x00"*(k/8-len(c)) + c
        print(hexlify(c))
      else:
        print(hexlify(padded_cleartext))
github alexmgr / pybleach / padding.py View on Github external
def __worker_pool_init(self, pool_size, task_queue_size=100, result_queue_size=1):
    self.__task_queue = mp.Queue(task_queue_size)
    self.__result_queue = mp.Queue(result_queue_size)
    self.__worker_pool = [RSAOracleWorker(self.oracle, self.callback, self.__task_queue, self.__result_queue, self.n, self.e)
                        for _ in xrange(pool_size)]
    self.__logger.info("Created %i workers in the processing pool" % (pool_size))
github zomux / deepy / deepy / dataset / sequence.py View on Github external
def _pad(self, side, length):
        """
        Pad sequences to given length in the left or right side.
        """
        if self._train_set:
            self._train_set = pad_dataset(self._train_set, side, length)
        if self._valid_set:
            self._valid_set = pad_dataset(self._valid_set, side, length)
        if self._test_set:
            self._test_set = pad_dataset(self._test_set, side, length)
github zomux / deepy / deepy / dataset / sequence.py View on Github external
def _pad(self, side, length):
        """
        Pad sequences to given length in the left or right side.
        """
        if self._train_set:
            self._train_set = pad_dataset(self._train_set, side, length)
        if self._valid_set:
            self._valid_set = pad_dataset(self._valid_set, side, length)
        if self._test_set:
            self._test_set = pad_dataset(self._test_set, side, length)
github zomux / deepy / deepy / dataset / sequence.py View on Github external
def _pad(self, side, length):
        """
        Pad sequences to given length in the left or right side.
        """
        if self._train_set:
            self._train_set = pad_dataset(self._train_set, side, length)
        if self._valid_set:
            self._valid_set = pad_dataset(self._valid_set, side, length)
        if self._test_set:
            self._test_set = pad_dataset(self._test_set, side, length)
github zomux / deepy / deepy / dataset / seq_mini_batch.py View on Github external
def _yield_data(self, subset):
        for i in xrange(0, len(subset), self.size):
            x_set, y_set = [], []
            batch = pad_dataset(subset[i:i + self.size], PADDING_SIDE, self.padding_length)
            for x, y in batch:
                x_set.append(x)
                y_set.append(y)
            x_set = np.array(x_set)
            y_set = np.array(y_set)
            if self._fix_batch_size and x_set.shape[0] != self.size:
                continue
            yield x_set, y_set
github alexmgr / pybleach / padding.py View on Github external
Traceback (most recent call last):
    ValueError: Cleartext too long to be conforming: max => 5 bytes, provided => 6 bytes
    >>> m = pad.conforming_message("12345")
    >>> m.startswith("\x00\x02")
    True
    >>> "\x00" not in m[2:10]
    True
    >>> "\x00" in m[10:]
    True
    >>> m[-6] == "\x00"
    True
    >>> m[-5:] == "12345"
    True
    """
    padding_len = self.k - len(data) - len(PKCS1_v15.HEADER) - len(PKCS1_v15.DELIMITER)
    if padding_len < PKCS1_v15.MIN_PAD_LEN:
      raise ValueError("Cleartext too long to be conforming: max => %i bytes, provided => %i bytes" % (self.k - PKCS1_v15.MIN_LEN, len(data)))
    random_padding = self.get_random_padding(padding_len)
    return PKCS1_v15.HEADER + random_padding + PKCS1_v15.DELIMITER + data
github alexmgr / pybleach / padding.py View on Github external
>>> m.startswith("\x00\x02")
    True
    >>> "\x00" not in m[2:10]
    True
    >>> "\x00" in m[10:]
    True
    >>> m[-6] == "\x00"
    True
    >>> m[-5:] == "12345"
    True
    """
    padding_len = self.k - len(data) - len(PKCS1_v15.HEADER) - len(PKCS1_v15.DELIMITER)
    if padding_len < PKCS1_v15.MIN_PAD_LEN:
      raise ValueError("Cleartext too long to be conforming: max => %i bytes, provided => %i bytes" % (self.k - PKCS1_v15.MIN_LEN, len(data)))
    random_padding = self.get_random_padding(padding_len)
    return PKCS1_v15.HEADER + random_padding + PKCS1_v15.DELIMITER + data
github alexmgr / pybleach / padding.py View on Github external
ValueError: Cleartext too long to be conforming: max => 5 bytes, provided => 6 bytes
    >>> m = pad.conforming_message("12345")
    >>> m.startswith("\x00\x02")
    True
    >>> "\x00" not in m[2:10]
    True
    >>> "\x00" in m[10:]
    True
    >>> m[-6] == "\x00"
    True
    >>> m[-5:] == "12345"
    True
    """
    padding_len = self.k - len(data) - len(PKCS1_v15.HEADER) - len(PKCS1_v15.DELIMITER)
    if padding_len < PKCS1_v15.MIN_PAD_LEN:
      raise ValueError("Cleartext too long to be conforming: max => %i bytes, provided => %i bytes" % (self.k - PKCS1_v15.MIN_LEN, len(data)))
    random_padding = self.get_random_padding(padding_len)
    return PKCS1_v15.HEADER + random_padding + PKCS1_v15.DELIMITER + data