Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labo_blockchain
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
denis.gremaud
labo_blockchain
Commits
c43dab07
Commit
c43dab07
authored
4 years ago
by
Denis Gremaud
Browse files
Options
Downloads
Patches
Plain Diff
OK
parent
17efafea
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
blockchain/input.txt
+0
-0
0 additions, 0 deletions
blockchain/input.txt
blockchain/test.txt
+0
-0
0 additions, 0 deletions
blockchain/test.txt
blockchain_gremaud_tefridj.py
+29
-44
29 additions, 44 deletions
blockchain_gremaud_tefridj.py
with
29 additions
and
44 deletions
blockchain/input.txt
+
0
−
0
View file @
c43dab07
No preview for this file type
This diff is collapsed.
Click to expand it.
blockchain/test.txt
+
0
−
0
View file @
c43dab07
No preview for this file type
This diff is collapsed.
Click to expand it.
blockchain_gremaud_tefridj.py
+
29
−
44
View file @
c43dab07
...
@@ -2,9 +2,10 @@
...
@@ -2,9 +2,10 @@
Usage:
Usage:
======
======
python blockchain_gremaud_tefridj.py file_name
python blockchain_gremaud_tefridj.py file_name
nonce
file_name: le nom du fichier pour commencer la blockchain
file_name: le nom du fichier pour commencer la blockchain
nonce: la taille du nonce voulu pour le minage
"""
"""
__authors__
=
(
"
Denis Gremaud
"
,
"
Yanis Tefridj
"
)
__authors__
=
(
"
Denis Gremaud
"
,
"
Yanis Tefridj
"
)
...
@@ -17,11 +18,10 @@ __version__= "1.0.1"
...
@@ -17,11 +18,10 @@ __version__= "1.0.1"
import
sys
import
sys
import
hashlib
import
hashlib
import
sys
import
sys
import
math
import
os
import
os
import
time
import
time
NONCE_SIZE
=
13
# number of numbre that should be 0 in nonce
NONCE_SIZE
=
13
"""
permet de lire un fichier
"""
permet de lire un fichier
...
@@ -58,7 +58,6 @@ def write_file_blockchain(input_file_path, data):
...
@@ -58,7 +58,6 @@ def write_file_blockchain(input_file_path, data):
file
.
write
(
data
)
file
.
write
(
data
)
file
.
close
()
file
.
close
()
"""
permet d
'
obtenir le hash d
'
un fichier en sha256
"""
permet d
'
obtenir le hash d
'
un fichier en sha256
Args:
Args:
...
@@ -75,18 +74,15 @@ def hash_data(data, print_hash=False):
...
@@ -75,18 +74,15 @@ def hash_data(data, print_hash=False):
print
(
'
hash : {}
'
.
format
(
hash_file
))
print
(
'
hash : {}
'
.
format
(
hash_file
))
return
hash_file
return
hash_file
"""
permet de lire un fichier et ensuite de le hash en sha256
def
print_last_block
(
input_file_path
,
block_current
,
time
):
print
(
"
-
"
*
90
)
Args:
print
(
"
Insertion de {}
"
.
format
(
input_file_path
))
file_name: le path ou nom du fichier a lire et a hash
print
(
"
Temps de minage : {} secondes
\n
"
.
format
(
time
))
print_hash: variable initialiser a false mais si true permet d
'
afficher le hash
print
(
"
Numéro du block : {}
"
.
format
(
block_current
.
block_number
[
0
]))
print
(
"
Hash du block précedent : 0x{}
"
.
format
(
block_current
.
block_prev_hash
.
hex
()))
Returns:
print
(
"
Nonce : {}
"
.
format
(
int
.
from_bytes
(
block_current
.
nonce
,
byteorder
=
'
big
'
)))
le hash du contenu du fichier
print
(
"
Hash du block courant : 0x{}
"
.
format
(
block_current
.
block_hash
))
print
(
"
-
"
*
90
)
"""
def
hash_file
(
input_file_path
,
print_hash
=
False
):
return
hash_data
(
read_file_blockchain
(
input_file_path
),
print_hash
)
class
blockchain
:
class
blockchain
:
...
@@ -118,12 +114,6 @@ class blockchain:
...
@@ -118,12 +114,6 @@ class blockchain:
self
.
first_block
=
block
self
.
first_block
=
block
self
.
total_block
+=
1
self
.
total_block
+=
1
def
read
(
self
,
input_file_path
):
read_b
=
block
(
input_file_path
)
read_b
.
block_number
,
read_b
.
block_prev_hash
=
read_file_blockchain
(
input_file_path
,
mode
=
2
)
read_b
.
block_hash
=
hash_file
(
input_file_path
)
return
read_b
class
block
:
class
block
:
def
__init__
(
self
,
file_path
,
block_number
=
0
,
block_prev_hash
=
0x00
,
block_obj
=
None
,
nonce
=
0
):
def
__init__
(
self
,
file_path
,
block_number
=
0
,
block_prev_hash
=
0x00
,
block_obj
=
None
,
nonce
=
0
):
...
@@ -134,41 +124,36 @@ class block:
...
@@ -134,41 +124,36 @@ class block:
self
.
block_obj
=
block_obj
self
.
block_obj
=
block_obj
self
.
block_hash
=
""
self
.
block_hash
=
""
def
print_block
(
input_file_path
,
block_current
):
print
(
"
Insertion de [
"
,
input_file_path
,
"
]
\n
"
)
print
(
"
Numéro du block :
"
,
block_current
.
block_number
[
0
])
print
(
"
Hash du block pointé : 0x
"
,
block_current
.
block_prev_hash
.
hex
())
print
(
"
Nonce :
"
,
int
.
from_bytes
(
block_current
.
nonce
,
byteorder
=
'
big
'
))
print
(
"
Hash du block inséré : 0x
"
,
block_current
.
block_hash
)
print
(
"
-
"
*
90
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
if
len
(
sys
.
argv
)
>
1
:
# on test si on a spécifié un nom de fichier à trier
if
len
(
sys
.
argv
)
>
1
:
# on test si on a spécifié un nom de fichier à trier
input_file_path
=
sys
.
argv
[
1
]
input_file_path
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
==
2
:
nonce_size
=
NONCE_SIZE
else
:
nonce_size
=
int
(
sys
.
argv
[
2
])
if
os
.
path
.
exists
(
input_file_path
)
==
True
:
if
os
.
path
.
exists
(
input_file_path
)
==
True
:
if
os
.
path
.
isdir
(
'
blockchain
'
)
is
not
True
:
if
os
.
path
.
isdir
(
'
blockchain
'
)
is
not
True
:
os
.
mkdir
(
'
blockchain
'
)
os
.
mkdir
(
'
blockchain
'
)
t
=
time
.
time
()
time_exec
=
time
.
time
()
blockchain
=
blockchain
(
input_file_path
,
NONCE_SIZE
)
blockchain
=
blockchain
(
input_file_path
,
nonce_size
)
t
=
time
.
time
()
-
t
time_exec
=
time
.
time
()
-
time_exec
print
(
"
\n
Temps d
'
insertion :
"
,
t
)
input_file_path
=
os
.
path
.
join
(
"
blockchain
"
,
input_file_path
)
print_last_block
(
input_file_path
,
blockchain
.
first_block
,
time_exec
)
first_block_read
=
blockchain
.
read
(
input_file_path
)
print_block
(
input_file_path
,
blockchain
.
first_block
)
input_file_path
=
input
(
"
\n
Entrer un nouveau chemin de fichier à insérer :
"
)
input_file_path
=
input
(
"
\n
Entrer un nouveau chemin de fichier à insérer :
"
)
while
input_file_path
!=
"
exit
"
:
while
input_file_path
!=
"
exit
"
:
if
os
.
path
.
exists
(
input_file_path
)
==
True
:
if
os
.
path
.
exists
(
input_file_path
)
==
True
:
block_input
=
block
(
input_file_path
,
blockchain
.
total_block
,
int
(
blockchain
.
first_block
.
block_hash
,
16
),
blockchain
.
first_block
)
block_input
=
block
(
input_file_path
,
blockchain
.
total_block
,
int
(
blockchain
.
first_block
.
block_hash
,
16
),
blockchain
.
first_block
)
t
=
time
.
time
()
time_exec
=
time
.
time
()
blockchain
.
insert
(
block_input
)
blockchain
.
insert
(
block_input
)
t
=
time
.
time
()
-
t
time_exec
=
time
.
time
()
-
time_exec
print
(
"
\n
Temps d
'
insertion :
"
,
t
)
input_file_path
=
os
.
path
.
join
(
"
blockchain
"
,
input_file_path
)
print_last_block
(
input_file_path
,
blockchain
.
first_block
,
time_exec
)
block_read
=
blockchain
.
read
(
input_file_path
)
print_block
(
input_file_path
,
blockchain
.
first_block
)
input_file_path
=
input
(
"
\n
Entrer un nouveau chemin de fichier à insérer :
"
)
input_file_path
=
input
(
"
\n
Entrer un nouveau chemin de fichier à insérer :
"
)
else
:
else
:
print
(
"
Le fichier spécifié n
'
existe pas !
"
)
# message affiché si le fichier n'existe pas
print
(
"
Le fichier spécifié n
'
existe pas !
"
)
# message affiché si le fichier n'existe pas
...
...
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