Skip to main content

BIS512 - Custom 512-bit Cryptographic Hash Function

⚠️ DO NOT USE THIS FOR REAL SECURITY ⚠️

This is an educational experiment only. It has not been audited and is almost certainly broken.

BIS512 uses a purely self‑contained implementation: no calls to OpenSSL, LibTomCrypt, or any other cryptographic library. All operations (rotations, additions, XOR, non‑linear functions, and constants) are manually implemented in the base language without reliance on pre‑existing hash primitives

Author: Biswajit Saha

education purpose only

Features

  • ✅ 512-bit output (128 hex characters)
  • ✅ ASIC-resistant - Fair CPU/GPU mining
  • ✅ Strong avalanche effect (49.7% bit change)
  • ✅ No collisions detected in 5000+ tests
  • ✅ Pure Python - Works everywhere, no compiler needed
  • ✅ Fast enough for blockchain applications(education only)

User Guide for BIS512 Hash Function

📦 Installation

pip install bis512

🚀 Basic Usage

# Import the hash function
from bis512 import hash_string, hash_bytes, hash_hex

# Method 1: Hash a string (returns hex string)
hash_value = hash_string("Hello, World!")
print(hash_value)
# Output: 128-character hexadecimal string

# Method 2: Hash bytes (returns bytes)
data = b"Blockchain data"
hash_bytes_result = hash_bytes(data)

# Method 3: Hash bytes and get hex
hex_result = hash_hex(b"Any input data")

💡 Quick Examples

from bis512 import hash

# Hash a simple message
print(hash("hello"))

# Hash a number
print(hash(str(12345)))

# Hash in a loop
for i in range(5):
    print(hash(f"message_{i}"))

# Hash from file
with open("myfile.txt", "rb") as f:
    file_hash = hash(f.read().decode())
    print(file_hash)

🔗 For Blockchain Applications

from bis512 import hash

# Block header hashing
def hash_block(previous_hash, transactions, nonce):
    block_data = f"{previous_hash}{transactions}{nonce}"
    return hash(block_data)

# Merkle tree hashing
def merkle_root(transactions):
    if len(transactions) == 1:
        return hash(transactions[0])
    
    new_level = []
    for i in range(0, len(transactions), 2):
        left = transactions[i]
        right = transactions[i+1] if i+1 < len(transactions) else left
        combined = left + right
        new_level.append(hash(combined))
    
    return merkle_root(new_level)

# Transaction hashing
def hash_transaction(sender, receiver, amount, timestamp):
    tx_data = f"{sender}{receiver}{amount}{timestamp}"
    return hash(tx_data)

🏗️ Mining Example

from bis512 import hash

def mine_block(previous_hash, transactions, difficulty):
    nonce = 0
    target = "0" * difficulty
    
    while True:
        block_data = f"{previous_hash}{transactions}{nonce}"
        block_hash = hash(block_data)
        
        if block_hash[:difficulty] == target:
            return nonce, block_hash
        nonce += 1

# Mine with difficulty 4
nonce, block_hash = mine_block("previous_hash_here", "transactions_data", 4)
print(f"Mined! Nonce: {nonce}, Hash: {block_hash}")

📝 Command Line Usage

# Quick hash from terminal
python -c "from bis512 import hash; print(hash('hello'))"

# Hash from file content
python -c "from bis512 import hash; print(hash(open('file.txt').read()))"

# Hash multiple inputs
python -c "from bis512 import hash; [print(hash(f'input_{i}')) for i in range(10)]"

🔐 Password Hashing Example

from bis512 import hash
import getpass

# Simple password hashing
password = getpass.getpass("Enter password: ")
password_hash = hash(password)
print(f"Password hash: {password_hash}")

# Verify password
def verify_password(input_password, stored_hash):
    return hash(input_password) == stored_hash

# Usage
stored = hash("mysecret123")
is_valid = verify_password("mysecret123", stored)
print(f"Password valid: {is_valid}")

📊 Performance Testing

from bis512 import hash
import time

# Test speed
start = time.time()
for i in range(100):
    hash(f"test_message_{i}")
end = time.time()

print(f"100 hashes in {end-start:.2f} seconds")
print(f"Speed: {100/(end-start):.0f} hashes/second")

🧪 Testing Different Inputs

from bis512 import hash

test_inputs = [
    "a",
    "aa", 
    "aaa",
    "Hello World",
    "Blockchain Technology",
    "1234567890",
    "The quick brown fox jumps over the lazy dog"
]

for inp in test_inputs:
    h = hash(inp)
    print(f"Input: {inp:40} -> Hash: {h[:16]}...")

⚠️ Important Notes

  1. Output is always 128 hex characters (512 bits)
  2. Same input always produces same hash
  3. Different inputs produce completely different hashes
  4. Pure Python - no external dependencies

🆘 Need Help?

# Check version
import bis512
print(f"BIS512 version: {bis512.__version__}")
print(f"Author: {bis512.__author__}")

# Get help
help(bis512)

✅ Quick Test

from bis512 import hash

# Test if working correctly
test_hash = hash("test")
print(f"Hash length: {len(test_hash)} characters")
print(f"Is 128 chars? {len(test_hash) == 128}")
print(f"First 16 chars: {test_hash[:16]}...")

📦 Uninstall

pip uninstall bis512

That's it! Your hash function is ready to use! 🚀

Metadata

Release files for bis512 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bis512 1.1.0
File Size Uploaded Provenance Actions
bis512-1.1.0.tar.gz 7.8 kB Without provenance Details for bis512-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bis512 1.1.0
File Interpreter ABI Platform Actions
bis512-1.1.0-py3-none-any.whl Python 3 none any Details for bis512-1.1.0-py3-none-any.whl

Total release size: 15.7 kB

Release files / bis512-1.1.0.tar.gz

Download URL bis512-1.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
50a14a19ee0af250cb1865960cec24be178cc7d072eeb2b22d40866a73bf5c49
BLAKE2b-256 checksum
How to use checksums
a8b967f7a2abb1e314fe692f24cf784801d846258fa8be9a2610b61a929ce351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / bis512-1.1.0-py3-none-any.whl

Download URL bis512-1.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58c457f1bbc8dcc306291a2aa51d29e58c6e6f2ebb149f4114abf8cfad527c0c
BLAKE2b-256 checksum
How to use checksums
df1ff99e7f601ee5b7fef2bda94825853e17ffa9d3faa024ca12c61de1798352
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for bis512 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page