1 line
1.1 KiB
Python
1 line
1.1 KiB
Python
|
import math,random,itertools,pyaudio
class primi:
def primo(n):
for i in range(3, int(math.sqrt(n)) + 1,2):
if n % i == 0: return False
return True
def prossimo(n):
if n % 2 == 0: n += 1
while True:
n += 2
if primi.primo(n): yield n
def lista(p, n):
return tuple([p for p in itertools.islice(primi.prossimo(p), n)])
class generatore:
def rumore(l):
audio = pyaudio.PyAudio()
output = audio.open(format = pyaudio.paInt8, channels = 1, output=True, rate = 50000)
for i in range(l*2500):
output.write(chr(int(random.random() * 25 + 1)))
output.close()
audio.terminate()
def leggirumore(l):
audio = pyaudio.PyAudio()
input = audio.open(format = pyaudio.paInt16, channels = 2, rate = 44100, input = True, frames_per_buffer = 1024)
return bytes(input.read(int(44100 / 1024 * l * 10)))
input.close()
audio.terminate()
def onetimepad(l):
dati = generatore.leggirumore(l)
numeri = [int(dati[i] * random.random() * l) for i in range(len(dati)) if dati[i] != 0]
inizio = int(random.random()*l)
return tuple([numeri[i] for i in range(inizio, inizio + l)])
|