Exemple #1
0
def main():
    # Generate random delay 
    time.sleep(utils.random_num(1, 5))
    # Get time
    t = int(time.time()) 
    # Init seed with current time
    prng = MT19937(t)
    # Sleep a bit 
    time.sleep(utils.random_num(1, 10))
    # Get value
    v = prng.get_num();
    print ("PRNG val = ", v)

    # Brute-force PRNG seed backwards in time
    t = int(time.time());
    print ("Time now = ", t)
    for i in range(20000000):
        seed = t-i
        # Try seed 
        prng = MT19937(seed)
        # Get number
        x = prng.get_num();
        # Check if seed found
        if x==v:
            print ("Seed is  = ", seed)
            break
Exemple #2
0
 def __init__(self, size):
     self.size = size
     self.position = [round(random_num()) for _ in range(self.size)]
     self.velocity = [random_num() for _ in range(self.size)]
     self.fitness = 0
     self.best_position = deepcopy(self.position)
     self.best_fitness = inf
     self.w = W
Exemple #3
0
 def update(self, particle: "Particle", t):
     global W, C1, C2
     for i in range(self.size):
         if random_num() < s(self.velocity[i]):
             self.position[i] = 1 - self.position[i]
             self.velocity[i] = self.w * self.velocity[i] + \
                                C1 * random_num() * (particle.best_position[i] - self.position[i]) + \
                                C2 * random() * (self.best_position[i] - self.position[i])
         self.w = W / (t + 1)
Exemple #4
0
def frosted_glass(img):
    img = img.convert('RGBA')  # 修改颜色通道为RGBA
    w, h = img.size
    for i in range(w - 8):
        for j in range(h - 8):
            position = (i, j)
            index = random_num(0, 8)
            temp = (i + index, j + index)
            colors = img.getpixel(temp)
            # log('colors', colors)
            img.putpixel(position, colors)
    img.save('frosted_glass.png')
    img.show()
Exemple #5
0
def test_02():
    arr = [random_num(1, 100) for i in range(8)]
    log('arr', arr)
    n = len(arr)
    new_arr = insert_sort(arr, n)
    log('new_arr', new_arr)
Exemple #6
0
def pwd_reset_token():
    return MT19937_encrypt(int(time.time()),
                           bytes([0] * utils.random_num(10, 20)))
Exemple #7
0
def encryption_oracle(plain):
    prefix = utils.random_bytes(utils.random_num(10, 20))
    return MT19937_encrypt(key, prefix + plain)
Exemple #8
0
#!python
import utils
from MT19937 import MT19937
import time

key = utils.random_num(0, 2**16)


def MT19937_encrypt(key, stream):
    prng = MT19937(key)
    return bytes([(x ^ prng.get_num()) & 0xFF for x in stream])


def MT19937_decrypt(key, stream):
    return MT19937_encrypt(key, stream)


def encryption_oracle(plain):
    prefix = utils.random_bytes(utils.random_num(10, 20))
    return MT19937_encrypt(key, prefix + plain)


def recover_key(plaintext):
    # Perform encryption by oracle
    ciphertext = encryption_oracle(plaintext)
    # Recover prefix size
    prefix_size = len(ciphertext) - len(plaintext)
    # Brute-force key
    for k in range(2**16):
        dec = MT19937_decrypt(k, ciphertext)
        if (dec[prefix_size:] == plaintext):
Exemple #9
0
def generate_color():
    r = random_num(64, 200)
    b = random_num(64, 200)
    g = random_num(64, 200)
    return (r, g, b)