๐ 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