Skip to content

A simple C++ program that solves Shamir's Secret Sharing polynomial reconstruction using basic mathematical operations to find the constant term from JSON test cases.

Notifications You must be signed in to change notification settings

SoftwareDeveloper-dhruv/HashiraCodingChallenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Features

Converts numbers from different bases (binary, hex, etc.) to decimal Uses basic interpolation to find polynomial coefficients Automatically processes JSON test case files Simple, student-friendly code structure No external libraries required

๐Ÿ“ Files

main.cpp - Main program source code testcase1.json - First test case with 4 shares testcase2.json - Second test case with 10 shares

๐Ÿ› ๏ธ Compilation & Usage Prerequisites

C++ compiler (g++, clang++, etc.) JSON test case files in the same directory

Compile bashg++ -o solver main.cpp Run bash./solver The program automatically processes both testcase1.json and testcase2.json files and outputs the secret for each test case. ๐Ÿ“Š Expected Output 3 39932017850922179524 ๐Ÿ“– How It Works

Base Conversion: Converts share values from various number bases to decimal Point Collection: Extracts (x, y) coordinate pairs from JSON data Polynomial Reconstruction: Uses basic mathematical interpolation Secret Extraction: Evaluates the polynomial at x=0 to find the constant term

๐Ÿงฎ Mathematical Approach The program uses elementary mathematics to solve the system:

For each point (xi, yi), calculate its contribution to f(0) Use the formula: weight = ฮ (0 - xj)/(xi - xj) for j โ‰  i Sum up: secret = ฮฃ(yi ร— weight)

๐Ÿ“ JSON Input Format json{ "keys": { "n": 4, "k": 3 }, "1": { "base": "10", "value": "4" }, "2": { "base": "2", "value": "111" } } Where:

n: Total number of shares k: Minimum shares needed to reconstruct secret Numbered entries: Individual shares with base and encoded value

๐Ÿค Contributing Feel free to fork this repository and submit pull requests for improvements. ๐Ÿ“„ License This project is open source and available under the MIT License. ๐ŸŽฏ Use Cases

Cryptography assignments Understanding secret sharing schemes Learning polynomial interpolation Educational demonstrations

About

A simple C++ program that solves Shamir's Secret Sharing polynomial reconstruction using basic mathematical operations to find the constant term from JSON test cases.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages