Skip to content

chinmaydwivedi/MATRIX_ENCRYPTION

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Matrix Encryption - Evolving Authentication System

License: MIT C++ JavaScript

A novel cryptographic authentication system that implements an evolving login scheme based on linear transformations of matrices over a prime field. This project demonstrates how mathematical concepts from linear algebra can be applied to create dynamic authentication mechanisms that change with each login attempt.

🔐 What is Matrix Encryption?

Unlike traditional static passwords, this system uses a 4x4 matrix that evolves through deterministic linear transformations with each authentication. The login "secret" changes over time, making it resistant to replay attacks and providing a unique authentication experience based on mathematical transformations.

Key Features

  • Evolving Authentication: Each login applies a new linear transformation to the base matrix
  • Mathematical Foundation: Built on Galois Field GF(257) with 4x4 matrix operations
  • Cross-Platform: Available as both C++ command-line tool and web interface
  • Deterministic Evolution: Uses SplitMix64 PRNG for reproducible transformations
  • SHA-256 Integration: Secure hashing for login code generation
  • JSON Key Format: Human-readable key storage with integrity checksums

🚀 Quick Start

Web Interface (Easiest)

Simply open web/index.html in any modern browser - no server required!

C++ Command Line

cd cpp
make
./matrix_login gen --username alice --out alice.key.json
./matrix_login code --key alice.key.json

🧮 How It Works

Mathematical Foundation

The system operates in Galois Field GF(257) (integers modulo 257) using 4x4 matrices:

  1. Initialization: At registration, a seed is derived from the current date/time, and a base matrix M₀ is generated
  2. Evolution: On the k-th login, a deterministic transform matrix T(k) is computed (invertible mod 257)
  3. Transformation: The current matrix evolves as: M_k = T(k) · T(k-1) · … · T(1) · M₀ (mod 257)
  4. Authentication: Login code is SHA-256(username || flattened(M_k)) (hexadecimal)
  5. Update: After successful login, the counter increments and the key evolves

Visual Representation

Registration → M₀ (Base Matrix)
     ↓
Login #1 → T(1) → M₁ = T(1) · M₀
     ↓
Login #2 → T(2) → M₂ = T(2) · M₁ = T(2) · T(1) · M₀
     ↓
Login #3 → T(3) → M₃ = T(3) · M₂ = T(3) · T(2) · T(1) · M₀
     ↓
...and so on

📋 Key Format

Keys are stored as JSON files with the following structure:

{
  "version": 1,
  "username": "alice",
  "modulus": 257,
  "dim": 4,
  "seedHex": "a1b2c3d4e5f6789012345678901234567890",
  "m0": [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]],
  "counter": 0,
  "checksum": "sha256_hash_of_canonical_fields"
}

Field Descriptions

  • seedHex: 16-byte hexadecimal seed derived from registration timestamp
  • m0: Base 4x4 matrix generated from the seed using SplitMix64 PRNG
  • counter: Current login attempt number (increments after each successful login)
  • checksum: SHA-256 hash of canonical fields to prevent casual tampering
  • version: Key format version for future compatibility

⚠️ Security Disclaimer

🚨 IMPORTANT: This is a research/educational project demonstrating novel cryptographic concepts.

  • DO NOT use for production authentication
  • ❌ No cryptographic security guarantees are provided
  • ❌ Deterministic evolution may leak structural information if observed
  • ✅ Intended for learning and experimentation only

💻 Installation & Usage

C++ Command Line Interface

Requirements: C++17 or newer, make

# Build the project
cd cpp
make

# Generate a new key
./matrix_login gen --username alice --out alice.key.json

# Get current login code
./matrix_login code --key alice.key.json

# Advance to next login (updates key)
./matrix_login advance --key alice.key.json --out alice.key.json

# Verify a login code
./matrix_login verify --key alice.key.json --code <hex_code>

Available Commands

Command Description
gen Create a new authentication key using current timestamp as seed
code Compute current login code for the key's counter (read-only)
advance Increment counter and save updated key for next login
verify Check if provided code matches current expected code

Web Interface

The web demo provides a user-friendly graphical interface:

# Simply open in any modern browser
open web/index.html

Web Features:

  • 🎲 Generate new keys with current timestamp seed
  • 📁 Load/save key JSON files
  • 🔍 View current login code and preview next code
  • ⏭️ Advance counter and download updated key
  • 📱 Responsive design works on desktop and mobile

🔄 Cross-Platform Compatibility

Both C++ CLI and web interface use identical algorithms:

  • Field: GF(257) with 4x4 matrices
  • PRNG: SplitMix64 seeded by seedHex + login index
  • Transform Generation: Retries until det(T(i)) ≠ 0 (mod 257)
  • Login Code: SHA-256(username || flattened(M_k))

This ensures perfect interoperability between implementations.

🏗️ Project Structure

MATRIX_ENCRYPTION/
├── cpp/                    # C++ command-line implementation
│   ├── main.cpp           # CLI entry point
│   ├── matrix.cpp/hpp     # Matrix operations
│   ├── gf257.cpp/hpp      # Galois Field arithmetic
│   ├── key.cpp/hpp        # Key management
│   ├── sha256.cpp/hpp     # SHA-256 hashing
│   └── Makefile           # Build configuration
├── web/                   # Web interface
│   ├── index.html         # Main web page
│   ├── logic.js           # Core authentication logic
│   ├── app.js             # UI interactions
│   └── styles.css         # Styling
└── README.md              # This file

🧪 Future Enhancements

  • Server Integration: Store expected counters server-side for true authentication
  • Matrix Dimensions: Configurable matrix sizes (currently 4x4)
  • Field Selection: Support for different prime fields beyond GF(257)
  • Key Derivation: Generate m0 purely from seed for smaller key files
  • Security Analysis: Formal cryptographic analysis of the scheme

📄 License

This project is released under the MIT License. See the project for educational and research purposes.


Made with ❤️ for the cryptographic community

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published