Summer School Information Security Lab1
Summer School Information Security Lab1
Student Number:
2. Software Requirements
Software:
• Python
• Visual Studio Code
Task1.2: Define a function to achieve the block record in task3.1, and write another
function to print the block according to the input index.
Task1.3: Put both functions into a class. Write a main program which creates an instance
of the class and can print desired block.
Task1.4: Comment your code, not just with inline comments (beginning ‘#’), but write a
docstring comment (one which is enclosed in triple quotes) for the function, detailing what
arguments the function takes and what it returns.
To start building the PoW blockchain, please create a Blockchain class. The __init__
method will consist of a variable called chain to store a list of all the blocks in the
blockchain.
The structure of generated blockchain is as below
{
index: 0, #Genesis Block
timestep: current time,
data: "Hello World!",
proof: 0,
previous_hash: '0'
} -> hash() -> 3s2351h
{
index: 1,
timestep: current time,
data: "Transaction A",
proof: 24912,
previous_hash: 3s2351h
} -> hash() -> 8fv743413
{
index: 2,
timestep: current time,
data: "Transaction B",
proof: 235724,
previous_hash: 8fv743413
} -> hash() -> 41j566d098
Task3.1: Write a block generate function to create the Genesis block on instantiation of
the class.
• Index: An index key will store the blockchain’s length. It is represented by the chain
variable in the __init__ method. Please use this variable to access each block in
the chain.
• Timestamp: The timestamp key will take a value of the current Date and Time the
block was created or mined.
• Date: The recorded information.
• Proof: This key will receive a proof value that will be passed to the function when
called. Note that this variable refers to the proof of work.
• Previous hash: Lastly, the previous hash key takes a value of previous_hash from
the function which is equivalent to the hash of the previous block.
Task3.2: Write a function that can input information into the block and record in
blockchain.
Task3.3: Access previous block by using a simple function. Please create a method that
gets the previous block in the chain.
6. Task 4: Reflection
After the completion of programming and testing please reflect, in a few lines, on your
understanding of the tasks and its significance. This is a chance for you to ask yourselves
“What you did?”, “What it means?”, and “What next?”, meaning what is the significance of
the undertaken task in the context of blockchain system and what you are learning in the
lecture. Try to be innovative and think outside the box. Please, do not provide a summary
of what you did as it will not be accepted. [Answer in the below space]
7. Lab Score
Marking Criteria Student’s Score
Demonstration (50%)
Lab Questions (10%)
Reflection (25%)
Adherence to coding good
practice (15%)