def keygen(n): """ Benaloh kriptosistemi ile public, private anahtarlari olusturup sirasiyla publickey.txt, privatekey.txt dosyalarina yazar. Arguments: n (int) : anahtar bit uzunlugu """ p = q = y = x = None while True: p = generate_random(n // 2) if (p - 1) % r == 0 and isprime(p) == 1 and math.gcd( r, int((p - 1) / r)) == 1: break while True: q = generate_random(n // 2) if isprime(q) == 1 and math.gcd(r, int(q - 1)) == 1: break n_ = p * q phi = (p - 1) * (q - 1) while True: y = randrange(1, n_) if math.gcd(y, n_) == 1: x = pow(y, phi * pow(r, -1, n_) % n_, n_) if x != 1: break with open("publickey.txt", "w+") as publickey_file: publickey_file.write(str(n_) + '\n' + str(y)) with open("privatekey.txt", "w+") as privatekey_file: privatekey_file.write(str(n_) + '\n' + str(phi) + '\n' + str(x))
def problem_10(): running_sum = 2 for value in xrange(3, int(2E6)+1, 2): if functions.isprime(value): running_sum += value return running_sum
def quadratic(a,b): primecount = 0 for n in range(100): if(isprime(n**2+a*n+b)==1): primecount += 1 else: break return(primecount)
def problem_3(N=600851475143): """ prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? """ all_factors = list(functions.factors(N)) max_prime = 1 for factor in all_factors: if factor > max_prime and functions.isprime(factor): max_prime = factor return max_prime
def problem_7(N=10001): """By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? """ count = 0 value = 0 while count < N: value += 1 if (not value % 2) and (value != 2): continue if functions.isprime(value): count += 1 return value
def keygen(n): w=[];wtotal=0;rcontrol=0;controlPrime=0 y=secrets.randbits(32) w.append(y) while len(w)!=8: total=0 total=sum(w) w.append(total+1) wtotal=sum(w) while controlPrime==0: qNumber= random.randint(wtotal,wtotal+1000) primeNumber=functions.isprime(qNumber) if(primeNumber==0): controlPrime=0 else: controlPrime=1 while rcontrol==0: rNumber= random.randint(1,1000) gcd_q_r=math.gcd(qNumber,rNumber) if(gcd_q_r==1): rcontrol=1 else: rcontrol=0 BArray=[] for i in w: b=(rNumber*i)%qNumber BArray.append(b) with open("publickey.txt","w") as public: for i in BArray: public.write(str(i)+" ") private_key=(w,qNumber,rNumber) with open("privatekey.txt","w") as private: for i in w: private.write(str(i)+" ") private.write("-"+str(qNumber)) private.write("-"+str(rNumber))
def generatePrimeNumber(n): p = 42 while not functions.isprime(p): p = generateBigNumber(n) return p
#!/usr/bin/python3 # -*- coding: utf-8 -*- from functions import isprime asal, n, p = 3, 9, 4 while (asal / (2 * p + 1) > 0.1): for m in range(1, 5): n += p if (isprime(n) == 1): asal += 1 p += 2 print(p + 1) # p kadar ekleyince karenin bir kenarı p+1 oluyor
#!/usr/bin/python3 # -*- coding: utf-8 -*- # By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. # What is the 10 001st prime number? from functions import isprime n,p = 0,1 while n<10001: p += 1 if(isprime(p)==1): n += 1 print(p)
import functions as func import numpy as np primes = [2, 3] value = 5 for i in np.arange(5, 2000000, 2): if func.isprime(i): primes.append(i) value += float(i) print(primes) print(value)
#!/usr/bin/python3 # -*- coding: utf-8 -*- # The prime 41, can be written as the sum of six consecutive primes: # 41 = 2 + 3 + 5 + 7 + 11 + 13 # This is the longest sum of consecutive primes that adds to a prime below one-hundred. # The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953. # Which prime, below one-million, can be written as the sum of the most consecutive primes? from functions import isprime maks=1 primes=[] for i in range(2,1000000): if isprime(i)==1: primes.append(i) for p in range(100,600): for i in range(len(primes)-p-1): sums = 0 for j in range(p): sums += primes[i+j] if (i==1) and sums>primes[-1]: break if(primes.count(sums)==1): maks=sums print(maks)
from functions import allprimes from functions import isprime import random deneme = 0 koltuklar=allprimes(100) while(len(koltuklar)>0): tercih = random.randint(1,200)%98 deneme += 1 if(isprime(tercih)==1 and koltuklar.count(tercih)==1): koltuklar.remove(tercih) print(deneme)
#!/usr/bin/python3 # -*- coding: utf-8 -*- # The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. # There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. # How many circular primes are there below one million? from functions import isprime sonuc = 13 for n in range(101, 1000000, 2): if (isprime(n) == 0): continue for p in range(len(str(n))): if (isprime(int(n)) == 0): break n = list(str(n)) n.append(n[0]) n.remove(n[0]) n = ''.join(str(i) for i in n) else: sonuc += 1 print(sonuc)
#!/usr/bin/python3 # -*- coding: utf-8 -*- # The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. # There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. # How many circular primes are there below one million? from functions import isprime sonuc = 13 for n in range(101,1000000,2): if(isprime(n)==0): continue for p in range(len(str(n))): if(isprime(int(n))==0): break n=list(str(n)) n.append(n[0]) n.remove(n[0]) n=''.join(str(i) for i in n) else: sonuc +=1 print(sonuc)
# Eoin Lees # Computing the primes. from functions import isprime # My list of Primes - TBD P = [] # Loop through all of the numbers we're checking for Primality. for i in range(2, 100): # If i is prime, then append to P. if isprime(i): P.append(i) # Print out our list print(P)
#!/usr/bin/python3 # -*- coding: utf-8 -*- # Find the sum of all the primes below two million. from functions import isprime toplam = 0 for i in range(2, 2000000): if isprime(i) == 1: toplam += i print(toplam)
#!/usr/bin/python3 # -*- coding: utf-8 -*- # The prime 41, can be written as the sum of six consecutive primes: # 41 = 2 + 3 + 5 + 7 + 11 + 13 # This is the longest sum of consecutive primes that adds to a prime below one-hundred. # The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953. # Which prime, below one-million, can be written as the sum of the most consecutive primes? from functions import isprime from functions import allprimes asal = allprimes(4000) toplam = [] for p in range(5,len(asal)): for a in range(0,len(asal)-p): if(isprime(sum(asal[a:a+p]))==1 and sum(asal[a:a+p])<1000000): toplam.append(sum(asal[a:a+p])) print(toplam[-1])
# 10001 inci asal sayıyı bulan kod. # 10001. prime number from functions import isprime n, p = 0, 1 while n < 10001: p += 1 if (isprime(p) == 1): n += 1 print(p)
from functions import allprimes from functions import isprime import random deneme = 0 koltuklar = allprimes(100) while (len(koltuklar) > 0): tercih = random.randint(1, 200) % 98 deneme += 1 if (isprime(tercih) == 1 and koltuklar.count(tercih) == 1): koltuklar.remove(tercih) print(deneme)
import numpy as np import scipy as sp import pandas as pd import functions as func import matplotlib.pyplot as plt primes = [2,3] number = 3 while len(primes) < 10001: if func.isprime(number): primes.append(number) number+=2 print(primes[-1])
#!/usr/bin/python3 # -*- coding: utf-8 -*- from functions import isprime asal,n,p = 3,9,4 while (asal/(2*p+1)>0.1): for m in range(1,5): n += p if(isprime(n)==1): asal += 1 p += 2 print(p+1)# p kadar ekleyince karenin bir kenarı p+1 oluyor