Exemple #1
0
def gen_random_tufo(form):
    iden = hexlify(random.bytes(16)).decode('utf8')
    props = {}
    for propname in form:
        if random.random() <= INTEGER_VAL_RATE:
            val = random.randint(-2 ** 62, 2 ** 63)
        else:
            val = random_string(random_val_len())
        props[propname] = val
    return (iden, props)
Exemple #2
0
def test_base64():
  random.seed(73101)
  for i in xrange(6):
    for n in xrange(20):
      s = random.bytes(n)
      ours = base64_encode(s)
      theirs = base64.b64encode(s)
      assert ours==theirs
      assert base64_decode(ours)==s
  for s in '====','&&&&','++==','+++=':
    try:
      base64_decode(s)
    except ValueError:
      pass
def get_random_bytes(size, seed):
    random.seed(seed)
    return random.bytes(size)
Exemple #4
0
 def test_bytes(self):
     random.seed(101)
     self.assertEqual(random.bytes(10), "_\xb32\x84\x0bFs\x8dQE")
from numpy.random import bytes

print repr(bytes(5))  # string of 5 random bytes
print repr(bytes(5))  # another string of 5 random bytes
Exemple #6
0
def rand_chars():
    n_bytes = random.randint(0, 10)
    return random.bytes(n_bytes).decode("latin1")
Exemple #7
0
'''[[-0.84341992 -0.51332541]
 [-0.0435368  -0.27530091]
 [-1.56306679 -0.79563099]
 [ 0.9305844   0.67776741]
 [ 0.69844026  0.17360206]]'''
x = random.normal(size=(5, 2))

# 产生5个,n=5,p=0.5的二项分布样本
x = random.binomial(n=5, p=0.5, size=5)
print(x)
a = np.arange(10)
print(a)
# 从a中有回放的随机采样7个
x = random.choice(a, 7)
print(x)
# 从a中无回放的随机采样7个
x = random.choice(a, 7, replace=False)
print(x)
# 对a进行乱序并返回一个新的array
b = random.permutation(a)
print(b)

# 对a进行in-place乱序
print('start', a)
random.shuffle(a)
print('end', a)
# 生成一个长度为9的随机bytes序列并作为str返回
# '\x96\x9d\xd1?\xe6\x18\xbb\x9a\xec'
x = random.bytes(9)
print(x)
Exemple #8
0
import sys
sys.path.append('../cryptoutils/')

import AES
import binascii
import numpy.random as rand
import time

secret = binascii.a2b_base64(
    'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgUm9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK'
)
key = rand.bytes(16)
prefix_len = rand.randint(1, 16)
prefix = rand.bytes(prefix_len)


def oracle(s):
    plain = prefix + s + secret
    return AES.ecb_encrypt(plain, key)


"""
	This is not a clean solution but it is a soultion i am proud of
	it doesn't break any assumptions (i guess i don't find block size but hey)
	it is a huge advancement over break_ecb
	
"""


def break_ecb():
def get_random_bytes(size, seed):
    with local_seed(seed):
        return random.bytes(size)
def get_random_bytes(size, seed):
    random.seed(seed)
    return random.bytes(size)