def solve(): w = [1, 2, 4, 9, 18, 35] q, r = 80, 29 #text = [55, 97, 21, 79, 100, 155] text = [42, 79, 78, 97, 154, 57] # Отнимаем единицу, так как индексация идет с нуля n = len(w) - 1 # Длина ключа k = len(text) - 1 # Длина шифротекста inverse_elem = inverse(r, q) s = [i * inverse_elem % q for i in text] matrix = [[0 for i in range(k + 1)] for j in range(n + 1)] m = [0 for i in range(k + 1)] for j in range(k + 1): for i in range(0, n): index = n - i matrix[j][index] = 0 if w[index] > s[j] else 1 s[j] -= matrix[j][index] * w[index] for i in range(1, n + 1): m[j] += matrix[j][i] * 2**(n - i) print(m)
def get_second_message(b1, b2, p, q1): return (q1 * b2 * inverse(b1, p)) % p
import sys sys.path.append('../') from Utils.inversion import inverse from Utils.log import log def check_abonent(r, g, y, p, s, e): return r == (g**s * y**e) % p p = 33107 q = 16553 g = 2902 y = 9107 r = 32607 if __name__ == '__main__': print(check_abonent(r, g, y, p, 9856, 15776)) print(check_abonent(r, g, y, p, 8108, 490)) print(check_abonent(r, g, y, p, 7309, 9987)) print(check_abonent(r, g, y, p, 1267, 155)) # find secret key inverse_elem = inverse(g, p) key = log(inverse_elem, y, p) print(key) # find a # a = log(g, r, p)
def rsa_key(r, a): euler = phi_new(r) return inverse(a, euler)
def get_sign(q, p, g, x, k): r = pow(g, k, p) s = ((q - x * r) * inverse(k, p - 1)) % (p - 1) return r, s