Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labo_secu3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
frederic.arroyo
labo_secu3
Commits
a4e5dff0
Verified
Commit
a4e5dff0
authored
11 months ago
by
frederic.arroyo
Browse files
Options
Downloads
Patches
Plain Diff
No commit message
No commit message
parent
e8487f5c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
elgamal.py
+25
-5
25 additions, 5 deletions
elgamal.py
fichier.signed.txt
+1
-1
1 addition, 1 deletion
fichier.signed.txt
privkey.txt
+1
-1
1 addition, 1 deletion
privkey.txt
pubkey.txt
+1
-1
1 addition, 1 deletion
pubkey.txt
with
28 additions
and
8 deletions
elgamal.py
+
25
−
5
View file @
a4e5dff0
from
typing
import
Tuple
from
random
import
randint
from
sys
import
argv
from
math
import
sqrt
from
math
import
sqrt
,
gcd
INPUT_NAME
=
"
fichier.txt
"
SIGNATURE_NAME
=
"
fichier.signed.txt
"
...
...
@@ -113,12 +113,31 @@ def get_random_generator(p: int) -> int:
return
generators
[
1
]
def
generate_key_pair
()
->
Tuple
[
Privkey
,
Pubkey
]:
p
=
get_random_prime
(
1000
,
10_000
)
g
=
get_random_generator
(
p
)
a
=
randint
(
0
,
p
-
1
)
# p = get_random_prime(1000, 10_000)
# g = get_random_generator(p)
# a = randint(0, p - 1)
p
=
7297
g
=
14
a
=
7057
A
=
pow
(
g
,
a
,
p
)
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
):
if
mode
==
0
:
# open the fichier.txt file and read its content into a string
...
...
@@ -128,7 +147,8 @@ def main(mode):
# algorithm
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
pubkey
.
write
(
PUBKEY_FILE
)
...
...
This diff is collapsed.
Click to expand it.
fichier.signed.txt
+
1
−
1
View file @
a4e5dff0
1117 2077
3621 5011
Il faut pas respirer la compote, ça fait tousser.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
privkey.txt
+
1
−
1
View file @
a4e5dff0
6659 6 337
\ No newline at end of file
7297 14 7057
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pubkey.txt
+
1
−
1
View file @
a4e5dff0
6659 6 1575
\ No newline at end of file
7297 14 1356
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment