0% found this document useful (0 votes)
9 views12 pages

Cryptocurrencies and Blockchain

The document outlines a series of tasks related to generating and verifying cryptographic hashes using various algorithms such as MD5, SHA-1, SHA-256, and bcrypt. It includes instructions for fetching article content, demonstrating the avalanche effect, and calculating hashes for files, highlighting the vulnerabilities of MD5. Additionally, it discusses the construction of Merkle trees from strings and file data, emphasizing the importance of secure hashing methods.

Uploaded by

humanayab140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Cryptocurrencies and Blockchain

The document outlines a series of tasks related to generating and verifying cryptographic hashes using various algorithms such as MD5, SHA-1, SHA-256, and bcrypt. It includes instructions for fetching article content, demonstrating the avalanche effect, and calculating hashes for files, highlighting the vulnerabilities of MD5. Additionally, it discusses the construction of Merkle trees from strings and file data, emphasizing the importance of secure hashing methods.

Uploaded by

humanayab140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Cryptocurrencies and Blockchain

Q1. Generate MD5, SHA-1, SHA-256, SHA512, SHA-3, BLAKE2, bcrypt and RIPEMD-160
hashes of your name string.

b. Import hashlib and bcrypt libraries. For bcrypt use command “pip install bcrypt”.

c. Take your name as an input string.

d. Convert your name string to bytes using function text.encode(). Here “text” is the input
string of your name.

e. For bcrypt you can use the following piece of code:

f. RIPEMD-160

Code:
Output:

Q2. Please repeat the above task taking the whole article of your choice from any
newspaper.

Personally, I like this one “https://thefinancialexpress.com.bd/views/reviews/silicon-valley-


banks-collapse-what happened-and-why-it-matters”.

Code:

Explanation of the Code:

1.pip install bcrypt requests beautifulsoup4 pycryptodome


2.Fetches the article content using requests and parses it using BeautifulSoup.

3.Extracts the article text by joining all paragraph elements.

4.Encodes the text into bytes (needed for hashing).

Output:

Q3. Use the same code above and demonstrate the “avalanche effect” by changing any
value in the input string of the article.

Code:
Output:

Conclusion

Cryptographic hash functions like SHA-256 rely on the avalanche effect to ensure no two
inputs produce similar outputs.

The avalanche effect is critical for cryptographic security. It ensures that small changes in
data lead to unpredictable, large-scale changes in the output, protecting against hacking,
tampering, and forgery.
Q4. In this task you need to calculate and verify the hash of this assignment file.

a. Upload the file to any online hash calculator service and calculate its hash using SHA-256
hash function.

b. Write a piece of code in which you take the online hash as input

c. Import the above mentioned file in your code, and calculate the hash using SHA-256 hash
function of hashlib python library.

d. Compare both hashes and verify it.

Code:

Output:

Q5. Create a text file containing unique content of your own choice. Write a program that
calculates SHA-256 hash of this file and demonstrates the avalanche effect on it.

Code:
Output:

6. Download the files named message1.bin and message2.bin from the following links:
Message1.bin: https://drive.google.com/file/d/14KwmJ-cD
bOrGz65Nh7jpJTEyoac3tpq/view?usp=drive_link

Message2.bin: https://drive.google.com/file/d/1U2K4cOks8Nb78kcJe6u4n8JP0HD2AhWk/
vie w?usp=drive_link

a. Import these files

b. Calculate the MD5 and SHA-1 hashes of the downloaded files.

c.Describe your findings and the reasons behind them.

Code:
Output:

Since both message1.bin and message2.bin have the same MD5 hash but different SHA-1
hashes, we can conclude:

Findings:

1. The files are not identical, because their SHA-1 hashes are different.

2. However, they produce the same MD5 hash, which suggests that they are crafted to
exploit MD5 hash collisions.
Reasons Behind This:

1. MD5 Collision Vulnerability:

o MD5 is cryptographically weak and susceptible to collisions, where two different


inputs can produce the same MD5 hash.

o Attackers can exploit this to create two distinct files with identical MD5 hashes,
which could be used for malicious purposes like digital signature forgery.

2. Intentional Manipulation:

o The files likely contain small changes that do not affect the MD5 hash but impact
the SHA-1 hash.

o Common collision techniques include modifying specific padding bytes or using


collision-generating algorithms.

3. SHA-1 Detects Differences:

o Unlike MD5, SHA-1 is more secure and detects even minor differences.

o The differing SHA-1 hashes prove that the files are not the same despite having
the same MD5 hash.

Conclusion:

 The files were likely crafted to demonstrate an MD5 hash collision.

 Relying on MD5 for integrity verification is insecure.

 SHA-1 (or stronger hashes like SHA-256) should be used for verifying file authenticity.

Q7. Generate a Merkle tree of the given text using an online hash calculator:
8. Write a program which does the following :
a.Takes eight random strings of your choice

b. Calculates their block and nodal hashes to construct a Merkle tree

c. Prints out the Merkle root of the tree

code:

Output:

Q9. Write a program which does the following :


a. Imports a file (use any file for this)

b. Parses the file into eight blocks

c. Calculates the SHA-256 hashes of each data block

d. Concatenates these hashes to generate a Merkle tree Prints out the Merkle root of the
tree

Code:
Output:

You might also like