コード例 #1
0
def decrypt(data, number):
    prime_num = prime.get_prime(number)

    cur_data = ord(data) - prime_num

    new_data = chr(cur_data % 128)

    return new_data
コード例 #2
0
ファイル: p012.py プロジェクト: benzheren/python-playground
def num_of_divisors(n):
    i = 0
    div = 1
    while n > 1:
        p = get_prime(i)
        j = 1
        while n % p == 0:
            j += 1
            n = n / p
        i += 1
        div *= j
    return div
コード例 #3
0
def weak_forge(l, attacks):
    if '(p-1)-метод' or 'итерация' in attacks:
        p = weak_low_p_1(l)
        q = weak_low_p_1(l)
        n = p * q
    else:
        p = get_prime(l)
        q = get_prime(l)
        n = p * q
    if 'атака-Винера' in attacks:
        if 'малый-модуль-шифрования' in attacks:
            e = 2
            while True:
                if math.gcd(e, (p - 1) * (q - 1)) != 1:
                    e += 1
                    continue
                d = reverse(e, (p - 1) * (q - 1))
                if d < (1 / 3 * (n**0.25)):
                    print("Weak parameters: ({}, {})".format(e, n))
                    return 0
                e += 1
        else:
            d = 2
            while True:
                if math.gcd(d, (p - 1) * (q - 1)) != 1:
                    d += 1
                    continue
                e = reverse(d, (p - 1) * (q - 1))
                print("Weak parameters: ({}, {})".format(e, n))
                return 0
    elif 'малый-модуль-шифрования' in attacks:
        e = 3
        while math.gcd(e, (p - 1) * (q - 1)) != 1:
            e += 1
        print("Weak parameters: ({}, {})".format(e, n))
        return 0
コード例 #4
0
ファイル: p49.py プロジェクト: kjunu/hello
def prime_permutations(digit):
	candidate = digit_filter(get_prime(pow(10,digit)-1), digit)
	
	i = 0
	do_nothing = 0
	while i < len(candidate):
		j = i
		while j < len(candidate):
			diff = []	
			diff.append(candidate[j]-candidate[i])
			
			if not has_diff_number(candidate[i]):
				j+=1
				continue
			elif diff[0] == 0:
				j+=1
				continue
			
			if not has_same_number(candidate[i],candidate[j]):
				j+=1
				continue
#			elif not digit_filter(diff,digit-1):
#				j+=1
#				continue
			try:
				candidate.index(candidate[i] + (diff[0] * 2))
			except ValueError:
				j+=1
				continue	
			
			if not has_same_number(candidate[i],candidate[j]+ diff[0]):
				j+=1
				continue
			
			print candidate[i],candidate[j],diff,candidate[i] + (diff[0] * 2)
			j+=1
		i+=1
コード例 #5
0
def encrypt(data, number):
    prime_num = prime.get_prime(number)

    new_data = chr(ord(data) + prime_num)

    return new_data
コード例 #6
0
ファイル: p035.py プロジェクト: benzheren/python-playground
'''
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 prime import get_prime, is_prime

result, i = {}, 0
p = get_prime(i)

def get_next_number(x):
    return (x % 10) * (10 ** (len(str(x)) - 1)) + x / 10

while p < 1000000:
    if result.get(p, 0):
        continue;
    else:
        t = get_next_number(p)
        while t != p:
            if is_prime(t):
                t = get_next_number(t)
            else:
                break
        if t == p:
            result[p] = 1
    i += 1
    p = get_prime(i)

print len(result)