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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine Priou
TP Introduction à la sécurité L2
Commits
8e86c38e
Commit
8e86c38e
authored
3 years ago
by
Antoine Priou
Browse files
Options
Downloads
Patches
Plain Diff
tp2
parent
33cd946b
Branches
main
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/hash_tbl.c
+3
-4
3 additions, 4 deletions
src/hash_tbl.c
tests/htbl_tests.c
+7
-6
7 additions, 6 deletions
tests/htbl_tests.c
tests/list_tests.c
+11
-9
11 additions, 9 deletions
tests/list_tests.c
tests/rho_pollard.c
+55
-8
55 additions, 8 deletions
tests/rho_pollard.c
with
76 additions
and
27 deletions
src/hash_tbl.c
+
3
−
4
View file @
8e86c38e
...
...
@@ -14,9 +14,8 @@ struct hash_tbl {
typedef
struct
hash_tbl
*
hash_tbl
;
hash_tbl
htbl_empty
(
size_t
(
*
h
)(
void
*
),
int
(
*
eq
)(
void
*
,
void
*
),
void
(
*
free
)(
void
*
)){
/*
hash_tbl htbl_empty(size_t (*h)(void*),int (*eq)(void*, void*), void (*free)(void*)){
}
int htbl_add(hash_tbl htbl, void* x){
...
...
@@ -27,4 +26,4 @@ int htbl_in(hash_tbl htbl, void* x){
void htbl_destroy(hash_tbl htbl){
}
*/
This diff is collapsed.
Click to expand it.
tests/htbl_tests.c
+
7
−
6
View file @
8e86c38e
...
...
@@ -23,6 +23,7 @@ void test_empty() {
printf
(
"test_empty OK
\n
"
);
}
/*
void test_add() {
char a[] = "Coucou 1";
char b[] = "Coucou 2";
...
...
@@ -62,14 +63,14 @@ void test_destroy() {
htbl_destroy(htbl);
printf("test_destroy OK\n");
}
*/
int
main
()
{
printf
(
"=== HTBL tests ===
\n
"
);
test_empty
();
test_add
();
test_in
();
test_destroy
();
//
test_add();
//
test_in();
//
test_destroy();
return
0
;
}
This diff is collapsed.
Click to expand it.
tests/list_tests.c
+
11
−
9
View file @
8e86c38e
...
...
@@ -62,6 +62,7 @@ void test_top(){
}
void
test_pop
(){
bignum_t
x
,
y
,
z
;
list_t
l
;
...
...
@@ -84,6 +85,7 @@ void test_pop(){
printf
(
"test_pop OK
\n
"
);
}
void
test_in_list
(){
bignum_t
x
,
y
,
z
;
list_t
l
;
...
...
This diff is collapsed.
Click to expand it.
tests/rho_pollard.c
+
55
−
8
View file @
8e86c38e
...
...
@@ -16,6 +16,35 @@ unsigned long int gcd(unsigned long int a, unsigned long int b){
return
old_r
;
}
int
f
(
long
int
x
){
return
(
x
*
x
+
1
)
;
}
bignum_t
fB
(
bignum_t
x
){
return
bignum_add
(
bignum_mul
(
x
,
x
),
bignum_from_int
(
1
))
;
}
unsigned
long
int
TP
(
unsigned
long
int
n
){
unsigned
long
int
x
=
2l
;
unsigned
long
int
y
=
2l
;
unsigned
long
int
z
=
1l
;
while
(
z
==
1
){
x
=
(
f
(
x
))
%
n
;
y
=
f
(
f
(
y
)
)
%
n
;
z
=
gcd
(
x
-
y
,
n
)
;
}
return
z
;
}
bignum_t
TPbigNum
(
bignum_t
n
){
bignum_t
x
=
bignum_from_int
(
2
)
;
bignum_t
y
=
bignum_from_int
(
2
)
;
bignum_t
z
=
bignum_from_int
(
1
)
;
while
(
z
==
bignum_from_int
(
1
)
){
x
=
bignum_mod
(
(
fB
(
x
)),
n
)
;
y
=
bignum_mod
(
fB
(
fB
(
y
)
),
n
)
;
z
=
bignum_gcd
(
bignum_sub
(
x
,
y
),
n
)
;
}
return
z
;
}
int
main
()
{
// En utilisant l'algorithme rho de Pollard, factorisez les entiers suivants
...
...
@@ -25,12 +54,29 @@ int main() {
unsigned
long
int
n4
=
15241
*
18119
;
unsigned
long
int
n5
=
366127l
*
416797l
;
unsigned
long
int
n6
=
15651941l
*
15485863l
;
unsigned
long
int
menfou
=
16128
*
3720
;
printf
(
"%lu %lu %lu %lu %lu %lu
\n
"
,
n1
,
n2
,
n3
,
n4
,
n5
,
n6
);
printf
(
"
\n
Fonction :
\n
"
);
printf
(
"%lu
\n
"
,
TP
(
n1
));
printf
(
"%lu
\n
"
,
TP
(
n2
));
printf
(
"%lu
\n
"
,
TP
(
n3
));
printf
(
"%lu
\n
"
,
TP
(
n4
));
printf
(
"%lu
\n
"
,
TP
(
n5
));
printf
(
"%lu
\n
"
,
TP
(
menfou
));
bignum_t
n7
,
n8
;
n7
=
bignum_mul
(
bignum_sub
(
bignum_pow
(
bignum_from_int
(
2
),
bignum_from_int
(
127
)),
n7
=
bignum_mul
(
bignum_sub
(
bignum_pow
(
bignum_from_int
(
2
),
bignum_from_int
(
127
)),
bignum_from_int
(
1
)),
bignum_sub
(
bignum_pow
(
bignum_from_int
(
2
),
bignum_from_int
(
61
)),
bignum_sub
(
bignum_pow
(
bignum_from_int
(
2
),
bignum_from_int
(
61
)),
bignum_from_int
(
1
)));
n8
=
bignum_mul
(
bignum_sub
(
bignum_pow
(
bignum_from_int
(
2
),
bignum_from_int
(
607
)),
...
...
@@ -38,10 +84,11 @@ int main() {
bignum_sub
(
bignum_pow
(
bignum_from_int
(
2
),
bignum_from_int
(
2203
)),
bignum_from_int
(
1
)));
printf
(
"oulah
\n
"
);
printf
(
"%lu
\n
"
,
TPbigNum
(
n7
));
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
\n
"
,
bignum_to_str
(
bignum_gcd
(
bignum_from_int
(
42
),
bignum_from_int
(
24
))));
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