示例#1
0
def mt():
    res = []
    n = 10000
    for i in xrange(n):
        #生成624位0到1的均匀分布数字
        res.append([
            math.sin(MT19937.MT19937(i).extract_number()),
            math.cos(MT19937.MT19937(i).extract_number())
        ])
    return res
示例#2
0
文件: make.py 项目: rocdat/STLIB
def birthConstant(size):
    # dx/dt = 

    # n is the size.
    # p is the propensity factor.
    # t is the time.
    # n * 2^(p t) = 2^t
    # n = 2^(t (1 - p))
    # log_2 n = t (1 - p)
    # (1/t) log_2 n = (1 - p)
    # p = 1 - (1/t) log_2 n 
    #p = 1 - (1./15.) * math.log(size) / math.log(2)

    # n 2^t = 2^15
    # n = 2^(15 - t)
    # log_2 n = 15 - t
    # t = 15 - log_2 n

    file = open('Birth' + str(size) + 'Constant.txt', 'w')
    # Propensity factors sum to unity.
    file.write('%s' % Birth.output(size, 1, lambda n: 1))
    # number of frames
    file.write('1\n')
    # list of frame times
    file.write('%f\n' % (15 - math.log(size) / math.log(2)))
    # maximum allowed steps
    file.write('0\n')
    # list of MT 19937 state
    file.write('%s' % MT19937.output())
    # number of trajectories
    file.write('1\n')
示例#3
0
def randomNumber():
    rand1 = random.randint(0, 100000)
    rand2 = random.randint(1, 50)
    generator = MT19937(rand1)
    for i in range(rand2):
        number = generator.getNumber()  # generate random salt
    return number
示例#4
0
def mt_dup():
    mt = MT19937.MT19937(0)
    new_mt_table = fill_mt_table()
    mt.get_gud(new_mt_table)
    token = str(mt.extract_number())
    for i in range(7):
        token += ":" + str(mt.extract_number())
    return base64.b64encode(token)
示例#5
0
文件: make.py 项目: rocdat/STLIB
def deathConstant(size, initialAmount):
    file = open('Death' + str(size) + 'Constant.txt', 'w')
    file.write('%s' % Death.output(size, initialAmount, lambda n: 1))
    # number of frames
    file.write('1\n')
    # list of frame times
    file.write('1000\n')
    # maximum allowed steps
    file.write('0\n')
    # list of MT 19937 state
    file.write('%s' % MT19937.output())
    # number of trajectories
    file.write('1\n')
示例#6
0
文件: make.py 项目: rocdat/STLIB
def decayingDimerizingConstant(size):
    file = open('DecayingDimerizing' + str(size) + '.txt', 'w')
    file.write('%s' % DecayingDimerizing.output(size))
    # number of frames
    file.write('1\n')
    # list of frame times
    file.write('30\n')
    # maximum allowed steps
    file.write('0\n')
    # list of MT 19937 state
    file.write('%s' % MT19937.output())
    # number of trajectories
    file.write('1\n')
示例#7
0
文件: make.py 项目: rocdat/STLIB
def immigrationConstant(size):
    file = open('Immigration' + str(size) + 'Constant.txt', 'w')
    file.write('%s' % Immigration.output(size, 0, 
                                         lambda n: 1. / size))
    # number of frames
    file.write('1\n')
    # list of frame times
    file.write('1000000\n')
    # maximum allowed steps
    file.write('0\n')
    # list of MT 19937 state
    file.write('%s' % MT19937.output())
    # number of trajectories
    file.write('1\n')
示例#8
0
文件: make.py 项目: rocdat/STLIB
def deathGeometric(size, initialAmount, factor):
    file = open('Death' + str(size) + 'Geometric' + str(factor) + '.txt', 'w')
    file.write('%s' % Death.output(size, initialAmount, 
                                   lambda n: factor**(float(n)/max(size-1,1))))
    # number of frames
    file.write('1\n')
    # list of frame times
    file.write('1000\n')
    # maximum allowed steps
    file.write('0\n')
    # list of MT 19937 state
    file.write('%s' % MT19937.output())
    # number of trajectories
    file.write('1\n')
示例#9
0
def oracle():
    random.seed()
    #Actual implmentation, for debugging lets use 1-3 seconds
    print("First time wait (5-60 seconds)")
    time.sleep(random.randrange(5, 60))
    print("Seeding")
    #time.sleep(random.randrange(1, 3))
    initInput = int(time.time())
    twister = MT19937.MT19937(initInput)
    print("Second wait (5-60 seconds)")
    time.sleep(random.randrange(5, 60))
    #time.sleep(random.randrange(1, 3))
    realOutput = twister.extract_number()
    print("The output was ", realOutput, "with a key of ", initInput)
    print("Bruteforcing for key")
    guessTime = int(time.time())
    testOutput = 0
    while testOutput != realOutput:
        twister = MT19937.MT19937(guessTime)
        testOutput = twister.extract_number()
        if testOutput == realOutput:
            print("The seed was ", guessTime)
        guessTime -= 1
    print("Done Bruteforcing")
示例#10
0
文件: make.py 项目: rocdat/STLIB
def immigrationGeometric(size, factor):
    file = open('Immigration' + str(size) + 'Geometric' + str(factor) +
                '.txt', 'w')
    sum = 0
    for n in range(size):
        sum += factor**(float(n)/max(size-1,1))
    file.write('%s' % Immigration.output(size, 0, 
                                         lambda n: factor**(float(n)/max(size-1,1)) / sum))
    # number of frames
    file.write('1\n')
    # list of frame times
    file.write('1000000\n')
    # maximum allowed steps
    file.write('0\n')
    # list of MT 19937 state
    file.write('%s' % MT19937.output())
    # number of trajectories
    file.write('1\n')
示例#11
0
文件: make.py 项目: rocdat/STLIB
def birthGeometric(size, factor):
    file = open('Birth' + str(size) + 'Geometric' + str(factor) + '.txt', 'w')
    # Propensity factors sum to unity.
    sum = 0
    for n in range(size):
        sum += factor**(float(n)/max(size-1,1))
    file.write('%s' % Birth.output(size, 1, 
                                   lambda n: factor**(float(n)/max(size-1,1)) / sum))
    # number of frames
    file.write('1\n')
    # list of frame times
    file.write('1000\n')
    # maximum allowed steps
    file.write('0\n')
    # list of MT 19937 state
    file.write('%s' % MT19937.output())
    # number of trajectories
    file.write('1\n')
示例#12
0
def mt19937_stream_cipher(plaintext, seed):
    '''
	This function receives a plaintext and a 16 bit seed to create a keystream using
	a MT19937 PRNG that will be used to create the ciphertext.
	We will note that the output of the PRNG is a 32 bit integer,we will convert it to 4
	characters in order to use the xor_strings function that we already wrote.
	Inputs:
		- plaintext: The text that will be encrypted.
		- seed: 16 bit seed that will be used to create the PRNG.
	Output:
		- The produced ciphertext.
	'''
    #Take only 16 bits of the given seed.
    rng = MT19937(seed & 0xffff)
    num_blocks = int(math.ceil(float(len(plaintext)) / 4))
    #Create the keystream.
    keystream = ""
    for i in range(num_blocks):
        produced_num = rng.extract_number()
        #Use struct module to convert integer to string.
        keystream += struct.pack("<L", produced_num)
    return xor_strings(plaintext, keystream)
示例#13
0
def test_password_token(token):
    '''
	Given some password reset token we will check if it was created using a PRNG seeded with the current
	time,we will take a range eps before and after the time and check the products of all the prng's seeded
	with these seeds.
	We will assume the token is the first result extracted from the temper function of the PRNG,
	otherwise it can be the 1000 extracted number from a prng and it will take a lot longer to discover
	if the seed that was used is the current time.
	Inputs:
		- token: Some password reset token.
	Outputs:
		- True if the token is the result of PRNG seeded with current time,false otherwise.
	'''
    curr_time = int(time.time())
    #Choose some random eps.
    eps = 100
    for i in range(curr_time - eps, curr_time + eps + 1):
        curr_prng = MT19937(int(i))
        #Extract a number and
        if (curr_prng.extract_number() == token):
            return True
    return False
示例#14
0
# token timeout, in minutes
TIMEOUT = 5		

render = web.template.render('templates/')
urls = ('/', 'index',
        '/forgot', 'forgot',
        '/register', 'register',
        '/reset', 'reset')

#Faking a user database.
user_dic = {"admin":"119ba0f0a97158cd4c92f9ee6cf2f29e75f5e05a"}
token_dic = {}

#Seed my super-secure PRNG using the OS
seed = int(os.urandom(4).encode("hex"), 16)
MT = MT19937.MT19937(seed)

class index:
	myform = form.Form(
		form.Textbox("username",
			form.notnull,
			description="Username",
			id='usernameBox'),
		form.Password("password",
			form.notnull,
			description="Password",
			id='passwordBox'),
		form.Button("Login",
			id='loginButton'))

	def GET(self):
示例#15
0
 def __init__(self, p, g):
     self.p = p
     self.g = g
     self.ab = MT19937(random.randint(0, p)).getNumber()
     self.key = 0
示例#16
0
  numberOfBins = int(sys.argv[3])
  # The recorded species.
  recordedSpecies = [int(x) for x in sys.argv[4:-1]]
  # The number of trajectories.
  numberOfTrajectories = int(sys.argv[-1])

  # 
  # Write the input file.
  #

  # Number of frames
  print '1'
  # List of frame times
  print endTime
  # Maximum allowed steps
  print maximumAllowedSteps
  # Number of species to record.
  print len(recordedSpecies)
  # List of species to record.
  print ('%s ' * len(recordedSpecies)) % tuple(recordedSpecies)
  # Number of bins.
  print numberOfBins
  # Number of parameters.
  print '0'
  # Empty line for the parameters.
  print ''
  # List of MT 19937 state
  sys.stdout.write(MT19937.output())
  # Number of trajectories
  print numberOfTrajectories
示例#17
0
import time
import random
import requests
import MT19937
import base64

twister = MT19937.MT19937(0)


def TaskI():
    oracle()


def TaskII():
    #Register a User so we can get tokens
    rObject = requests.post('http://localhost:3030/register',
                            data={
                                'user': '******',
                                'password': '******'
                            })

    #Variable that represents internal state of twister
    internalState = [0] * 624
    for i in range(78):  #should be 78
        #Generate token
        rObject = requests.post('http://localhost:3030/forgot',
                                data={'user': '******'})
        #Parse this token from http
        token = parseToken(rObject.text)
        #Turn Base64 token output into uint32 that comes from twister
        twisterOutput = tokenToInt(token)