Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP Introduction à la sécurité L2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yacine Kessal
TP Introduction à la sécurité L2
Commits
66a463b5
Commit
66a463b5
authored
Apr 1, 2022
by
Yacine Kessal
Browse files
Options
Downloads
Patches
Plain Diff
Tp 2
parent
06dc3338
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/list.c
+0
-3
0 additions, 3 deletions
src/list.c
tests/rho_pollard.c
+50
-3
50 additions, 3 deletions
tests/rho_pollard.c
with
50 additions
and
6 deletions
src/list.c
+
0
−
3
View file @
66a463b5
...
@@ -33,7 +33,6 @@ void* list_pop(list_t* l){
...
@@ -33,7 +33,6 @@ void* list_pop(list_t* l){
return
NULL
;
return
NULL
;
list_t
new_head
=
(
*
l
)
->
next
;
list_t
new_head
=
(
*
l
)
->
next
;
void
*
res
=
(
*
l
)
->
val
;
void
*
res
=
(
*
l
)
->
val
;
>>>>>>>
prof
/
main
free
(
*
l
);
free
(
*
l
);
*
l
=
new_head
;
*
l
=
new_head
;
return
res
;
return
res
;
...
@@ -41,7 +40,6 @@ void* list_pop(list_t* l){
...
@@ -41,7 +40,6 @@ void* list_pop(list_t* l){
void
*
list_top
(
list_t
l
){
void
*
list_top
(
list_t
l
){
return
list_is_empty
(
l
)
?
NULL
:
l
->
val
;
return
list_is_empty
(
l
)
?
NULL
:
l
->
val
;
>>>>>>>
prof
/
main
}
}
void
list_destroy
(
list_t
l
,
void
(
*
free
)(
void
*
)){
void
list_destroy
(
list_t
l
,
void
(
*
free
)(
void
*
)){
...
@@ -61,5 +59,4 @@ void* list_in(list_t l, void* x, int (*eq)(void*, void*)){
...
@@ -61,5 +59,4 @@ void* list_in(list_t l, void* x, int (*eq)(void*, void*)){
unsigned
long
int
list_len
(
list_t
l
){
unsigned
long
int
list_len
(
list_t
l
){
return
list_is_empty
(
l
)
?
0
:
l
->
id
;
return
list_is_empty
(
l
)
?
0
:
l
->
id
;
>>>>>>>
prof
/
main
}
}
This diff is collapsed.
Click to expand it.
tests/rho_pollard.c
+
50
−
3
View file @
66a463b5
...
@@ -16,13 +16,53 @@ unsigned long int gcd(unsigned long int a, unsigned long int b){
...
@@ -16,13 +16,53 @@ unsigned long int gcd(unsigned long int a, unsigned long int b){
return
old_r
;
return
old_r
;
}
}
unsigned
long
int
f
(
unsigned
long
x
){
return
x
*
x
+
1
;
}
unsigned
long
int
Pollard
(
unsigned
long
n
){
unsigned
long
int
x
=
2l
;
unsigned
long
int
y
=
2l
;
unsigned
long
int
d
=
1l
;
while
(
d
==
1l
){
x
=
f
(
x
)
%
n
;
y
=
f
(
f
(
y
))
%
n
;
d
=
gcd
(
x
-
y
,
n
);
}
return
d
;
}
bignum_t
Pollard2
(
bignum_t
n
){
bignum_t
f2
(
bignum_t
x
){
return
bignum_pow
(
x
,
2
)
+
1
;
}
unsigned
long
int
x1
=
2l
;
unsigned
long
int
y2
=
2l
;
unsigned
long
int
d3
=
1l
;
bignum_t
x
=
bignum_from_int
(
x1
);
bignum_t
y
=
bignum_from_int
(
y2
);
bignum_t
d
=
bignum_from_int
(
d3
);
while
(
d
==
bignum_from_int
(
1l
)){
x
=
bignum_mod
(
f2
(
x
),
n
);
y
=
bignum_mod
(
f2
(
f2
(
y
)),
n
);
d
=
gcd
(
x
-
y
,
n
);
}
return
d
;
}
int
main
()
{
int
main
()
{
// En utilisant l'algorithme rho de Pollard, factorisez les entiers suivants
// En utilisant l'algorithme rho de Pollard, factorisez les entiers suivants
unsigned
long
int
n1
=
17
*
113
;
unsigned
long
int
n1
=
17
*
113
;
unsigned
long
int
n2
=
239
*
431
;
unsigned
long
int
n2
=
239
*
431
;
unsigned
long
int
n3
=
3469
*
4363
;
unsigned
long
int
n3
=
3469
*
4363
;
unsigned
long
int
n4
=
15241
*
18119
;
unsigned
long
int
n4
=
15241
*
18119
;
unsigned
long
int
n5
=
366127l
*
416797l
;
unsigned
long
int
n5
=
366127l
*
416797l
;
unsigned
long
int
n6
=
15651941l
*
15485863l
;
unsigned
long
int
n6
=
15651941l
*
15485863l
;
...
@@ -42,6 +82,13 @@ int main() {
...
@@ -42,6 +82,13 @@ int main() {
printf
(
"PGCD(42,24) = %lu
\n
"
,
gcd
(
42
,
24
));
printf
(
"PGCD(42,24) = %lu
\n
"
,
gcd
(
42
,
24
));
printf
(
"PGCD(42,24) = %s
\n
"
,
bignum_to_str
(
bignum_gcd
(
bignum_from_int
(
42
),
bignum_from_int
(
24
))));
printf
(
"PGCD(42,24) = %s
\n
"
,
bignum_to_str
(
bignum_gcd
(
bignum_from_int
(
42
),
bignum_from_int
(
24
))));
printf
(
"Pollard n1 = %ld
\n
"
,
Pollard
(
n1
));
printf
(
"Pollard n2 = %ld
\n
"
,
Pollard
(
n2
));
printf
(
"Pollard n3 = %ld
\n
"
,
Pollard
(
n3
));
printf
(
"Pollard n4 = %ld
\n
"
,
Pollard
(
n4
));
printf
(
"Pollard n5 = %ld
\n
"
,
Pollard
(
n5
));
printf
(
"Pollard n6 = %ld
\n
"
,
Pollard
(
n6
));
printf
(
"Pollard n7 = %d
\n
"
,
bignum_to_str
(
Pollard2
(
n7
)));
printf
(
"Pollard n8 = %ld
\n
"
,
Pollard
(
n8
));
return
0
;
return
0
;
}
}
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