Skip to content
Snippets Groups Projects
Verified Commit a4e5dff0 authored by frederic.arroyo's avatar frederic.arroyo
Browse files

No commit message

No commit message
parent e8487f5c
No related branches found
No related tags found
No related merge requests found
from typing import Tuple from typing import Tuple
from random import randint from random import randint
from sys import argv from sys import argv
from math import sqrt from math import sqrt, gcd
INPUT_NAME="fichier.txt" INPUT_NAME="fichier.txt"
SIGNATURE_NAME="fichier.signed.txt" SIGNATURE_NAME="fichier.signed.txt"
...@@ -113,12 +113,31 @@ def get_random_generator(p: int) -> int: ...@@ -113,12 +113,31 @@ def get_random_generator(p: int) -> int:
return generators[1] return generators[1]
def generate_key_pair() -> Tuple[Privkey, Pubkey]: def generate_key_pair() -> Tuple[Privkey, Pubkey]:
p = get_random_prime(1000, 10_000) # p = get_random_prime(1000, 10_000)
g = get_random_generator(p) # g = get_random_generator(p)
a = randint(0, p - 1) # a = randint(0, p - 1)
p = 7297
g = 14
a = 7057
A = pow(g, a, p) A = pow(g, a, p)
return Privkey(p, g, a), Pubkey(p, g, A) return Privkey(p, g, a), Pubkey(p, g, A)
def xgcd(a,b):
prevx , x = 1 , 0
prevy , y = 0 , 1
while b:
q = a//b
x, prevx = prevx - q*x, x
y, prevy = prevy - q*y, y
a, b = b, a % b
return a, prevx, prevy
def generate_k(p: int) -> int:
k = randint(1, p - 2)
while gcd(k, p - 1) != 1:
k = randint(1, p - 2)
return k
def main(mode): def main(mode):
if mode == 0: if mode == 0:
# open the fichier.txt file and read its content into a string # open the fichier.txt file and read its content into a string
...@@ -128,7 +147,8 @@ def main(mode): ...@@ -128,7 +147,8 @@ def main(mode):
# algorithm # algorithm
privkey, pubkey = generate_key_pair() privkey, pubkey = generate_key_pair()
signature = sign(hash(m), 5, privkey) k = generate_k(privkey.p)
signature = sign(hash(m), k, privkey)
# write our files # write our files
pubkey.write(PUBKEY_FILE) pubkey.write(PUBKEY_FILE)
......
1117 2077 3621 5011
Il faut pas respirer la compote, ça fait tousser. Il faut pas respirer la compote, ça fait tousser.
\ No newline at end of file
6659 6 337 7297 14 7057
\ No newline at end of file \ No newline at end of file
6659 6 1575 7297 14 1356
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment