Skip to content

Python + NumPy implementation of SHA-256 (FIPS 180-4), including padding, message schedule, compression function, full hash, tests vs hashlib, and a password-cracking demonstration.

Notifications You must be signed in to change notification settings

NathanCarr10/Computational-Theory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Secure Hash Standard - Assessment Repository

Computational Theory - ATU Galway

Nathan Carr (G00410214)

This repository contains my work for the Secure Hash Standard (FIPS 180-4) assessment.
All solutions are implemented and explained in the main notebook: problems.ipynb

My aim was to present the notebook in a clear and structured way for someone who is comfortable with Python and basic cryptography, but may not be familiar with the internal workings of SHA-256. Each problem is broken down with explanations, code, and tests so that the full process can be followed without additional context.


Setup and Running the Code

Requirements

  • Python 3.8+
  • NumPy
  • Standard library modules (hashlib, os, etc.)

Installation

  1. Clone this repository:

    git clone https://github.com/NathanCarr10/Computational-Theory.git
    cd Computational-Theory
  2. Install dependencies:

    pip install numpy
  3. Open and run the notebook:

    jupyter notebook problems.ipynb

    Or use VS Code with the Jupyter extension and select a Python kernel.

Reproducibility

All cells are designed to run sequentially from top to bottom. There are no external data dependencies—all test data is generated within the notebook.

Each code cell is self-contained and includes comments explaining its purpose. Markdown cells provide context and theoretical background.


Repository Contents

├── problems.ipynb # Main assessment notebook with full solutions

├── roughwork.ipynb # Scratch/testing notebook (not part of final marking, just my working area)

├── requirements.txt # Allowed packages for the assignment

└── README.md # This file


What Each Problem Covers

Problem 1 - Binary Word Operations

I implemented the core 32-bit operations used by SHA-256, including Ch, Maj, Σ0, Σ1, σ0 and σ1.
These are all wrapped as np.uint32 to match the behaviour in the Secure Hash Standard.
I also included tests that show the expected bitwise behaviour.

Problem 2 - SHA-256 Constants

I generated the first 64 prime numbers, took the fractional parts of their cube roots, and extracted the first 32 bits just like FIPS 180-4 describes.
I then verified that my computed constants match the official constants exactly.

Problem 3 - Padding and Message Blocks

I implemented the SHA-256 padding rules, turning any input message into 512-bit blocks.
I tested edge cases (like messages of length 55, 56, and 57 bytes) to make sure the padding matches the standard perfectly.

Problem 4 - Full SHA-256 Hash Function

I built the message schedule (W[0..63]) and the compression function (the 64 rounds), using the functions from earlier problems.
Finally, I wrote sha256_custom(msg) and confirmed that it matches Python’s hashlib.sha256 on a variety of standard test messages.

Problem 5 - Password Hashing and Security

I used SHA-256 to demonstrate a simple dictionary attack on three given password hashes.
After recovering the passwords, I explained why hashing passwords with just SHA-256 is insecure and discussed better alternatives like PBKDF2, bcrypt, and Argon2, along with salts, peppers, and rate limiting.


Running the Notebook

  1. Install the required packages:
pip install -r requirements.txt


Launch Jupyter:

Open problems.ipynb and run the cells in order.

Everything is self-contained, and all tests run automatically.

About

Python + NumPy implementation of SHA-256 (FIPS 180-4), including padding, message schedule, compression function, full hash, tests vs hashlib, and a password-cracking demonstration.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published