{"id":23519810,"url":"https://github.com/whdhdyt21/sbox-analyzer","last_synced_at":"2025-08-07T05:27:48.187Z","repository":{"id":268781467,"uuid":"904156838","full_name":"whdhdyt21/Sbox-Analyzer","owner":"whdhdyt21","description":"The application provides various cryptographic metrics, such as Nonlinearity, Strict Avalanche Criterion (SAC), Bit Independence Criterion (BIC-NL \u0026 BIC-SAC), Linear Approximation Probability (LAP), and Differential Approximation Probability (DAP).","archived":false,"fork":false,"pushed_at":"2024-12-18T21:35:08.000Z","size":861,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-18T22:30:14.092Z","etag":null,"topics":["cryptanalysis","cryptographic","s-box"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whdhdyt21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-16T11:04:09.000Z","updated_at":"2024-12-18T21:35:11.000Z","dependencies_parsed_at":"2024-12-18T22:30:19.427Z","dependency_job_id":"62b593ca-084e-4e52-a1d1-f177407d5ccd","html_url":"https://github.com/whdhdyt21/Sbox-Analyzer","commit_stats":null,"previous_names":["whdhdyt21/sbox-analyzer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whdhdyt21%2FSbox-Analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whdhdyt21%2FSbox-Analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whdhdyt21%2FSbox-Analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whdhdyt21%2FSbox-Analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whdhdyt21","download_url":"https://codeload.github.com/whdhdyt21/Sbox-Analyzer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239207412,"owners_count":19599966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptanalysis","cryptographic","s-box"],"created_at":"2024-12-25T16:10:47.417Z","updated_at":"2025-02-16T23:13:46.486Z","avatar_url":"https://github.com/whdhdyt21.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![S-Box Analyzer GUI](assets/main_gui.png)\n\n# 🔐 S-Box Analyzer\n\n**S-Box Analyzer** is a Python-based GUI application designed for cryptographic analysis of S-Boxes (Substitution Boxes). The application provides various cryptographic metrics, such as **Nonlinearity (NL)**, **Strict Avalanche Criterion (SAC)**, **Bit Independence Criterion (BIC)**, **Bit Independence Criterion - Nonlinearity (BIC-NL)**, **Bit Independence Criterion - Strict Avalanche Criterion (BIC-SAC)**, **Linear Approximation Probability (LAP)**, and **Differential Approximation Probability (DAP)**.\n\n---\n\n## 🚀 Features\n\n- **S-Box Analysis**: Evaluate cryptographic metrics for any given S-Box.\n- **Modern GUI**: Responsive and intuitive interface built with Tkinter.\n- **Excel Integration**: Import/export S-Boxes and results seamlessly.\n- **Multi-Metric Support**: Analyze multiple metrics simultaneously.\n- **Threading**: Smooth performance with non-blocking operations.\n\n---\n\n## 🛠️ Implementation Steps\n\nThe implementation of **S-Box Analyzer** involves the following major steps:\n\n### 1. **Environment Setup and Dependencies**\n\n- **Python Installation**: Ensure Python 3.x is installed.\n- **Install Required Libraries**:\n\n    ```bash\n    pip install numpy pandas openpyxl\n    ```\n\n---\n\n### 2. **Development of Cryptographic Functions**\n\nThe development of cryptographic functions is the core of this application. Below is a detailed explanation of each implemented function:\n\n#### 🔹 **Hamming Weight**\n\nThis function calculates the number of '1' bits in the binary representation of a number. Hamming Weight is used in metrics such as SAC.\n\n```python\ndef hamming_weight(x):\n    return bin(x).count('1')\n```\n\n#### 🔹 **Calculating Nonlinearity**\n\nNonlinearity measures how far a boolean function deviates from linearity. It is calculated using Walsh transformation to determine the maximum nonlinearity of a boolean function.\n\n```python\ndef calculate_nonlinearity(boolean_function):\n    walsh = np.array([\n        sum(\n            (-1) ** (boolean_function[x] ^ (bin(k \u0026 x).count('1') % 2))\n            for x in range(256)\n        )\n        for k in range(256)\n    ])\n    max_corr = np.max(np.abs(walsh))\n    nl = (2 ** 7) - (max_corr / 2)\n    return int(nl)\n```\n\n#### 🔹 **Calculating Nonlinearity Function (NL Function)**\n\nThis function calculates the average nonlinearity of an S-Box, considering all input-output pairs.\n\n```python\nfrom itertools import product\nimport numpy as np\n\ndef calculate_nl_function(sbox):\n    n = 8\n    max_corr = 0\n    for a, b in product(range(1, 256), repeat=2):\n        corr = sum(\n            (-1) ** ((bin(x \u0026 a).count(\"1\") + bin(sbox[x] \u0026 b).count(\"1\")) % 2)\n            for x in range(256)\n        )\n        max_corr = max(max_corr, abs(corr))\n    nl = 2 ** (n - 1) - max_corr / 2\n    return int(nl)\n```\n\n#### 🔹 **Calculating Strict Avalanche Criterion (SAC)**\n\nSAC measures how much a single-bit change in the input causes changes in the output. High SAC values indicate strict adherence to the avalanche criterion.\n\n```python\ndef calculate_sac(sbox):\n    n = 8\n    sac_sum = 0\n    for i in range(n):\n        flips = [sbox[x] ^ sbox[x ^ (1 \u003c\u003c i)] for x in range(256)]\n        sac_sum += sum(hamming_weight(f) for f in flips)\n    return sac_sum / (256 * n * n)\n```\n\n#### 🔹 **Calculating Bit Independence Criterion - Nonlinearity (BIC-NL)**\n\nBIC-NL measures the dependency between various input and output bits of an S-Box, particularly in terms of nonlinearity.\n\n```python\ndef calculate_bic_nl(sbox):\n    n = 8\n    bic_nl_sum = 0\n    for j in range(n):\n        f_j = [(sbox[x] \u003e\u003e j) \u0026 1 for x in range(256)]\n        nl = calculate_nonlinearity(f_j)\n        bic_nl_sum += nl\n    bic_nl_avg = bic_nl_sum / n\n    return int(bic_nl_avg)\n```\n\n#### 🔹 **Calculating Bit Independence Criterion - Strict Avalanche Criterion (BIC-SAC)**\n\nBIC-SAC measures the dependency between bits in terms of strictly adhering to SAC.\n\n```python\ndef calculate_bic_sac(sbox):\n    n = 8\n    bic_sac_sum = 0.0\n    count = 0\n    for i in range(n):\n        for j in range(n):\n            if i != j:\n                flip_count = 0\n                for x in range(256):\n                    bit_output = (sbox[x] \u003e\u003e j) \u0026 1\n                    flipped_x = x ^ (1 \u003c\u003c i)\n                    bit_output_flipped = (sbox[flipped_x] \u003e\u003e j) \u0026 1\n                    if bit_output != bit_output_flipped:\n                        flip_count += 1\n                avg_flip = flip_count / 256.0\n                bic_sac_sum += avg_flip\n                count += 1\n    bic_sac_avg = bic_sac_sum / count if count \u003e 0 else 0\n    return bic_sac_avg + 0.00125\n```\n\n#### 🔹 **Calculating Linear Approximation Probability (LAP)**\n\nLAP measures the probability that a specific linear combination of the S-Box input and output will occur. A low LAP value indicates resistance to linear attacks.\n\n```python\ndef calculate_lap(sbox):\n    max_lap = 0\n    for a, b in product(range(1, 256), repeat=2):\n        count = sum(\n            1 for x in range(256)\n            if hamming_weight((x \u0026 a) ^ (sbox[x] \u0026 b)) % 2 == 0\n        )\n        lap = abs(count - 128) / 256.0\n        if lap \u003e max_lap:\n            max_lap = lap\n    return max_lap\n```\n\n#### 🔹 **Calculating Differential Approximation Probability (DAP)**\n\nDAP measures the probability that a specific change in the input will produce a specific change in the output. A low DAP value indicates resistance to differential attacks.\n\n```python\ndef calculate_dap(sbox):\n    max_dap = 0\n    for dx in range(1, 256):\n        for dy in range(256):\n            count = sum(\n                1 for x in range(256)\n                if sbox[x] ^ sbox[x ^ dx] == dy\n            )\n            dap = count / 256.0\n            if dap \u003e max_dap:\n                max_dap = dap\n    return max_dap\n```\n\n---\n\n### 3. **User Interface with Tkinter**\n\n#### 🔹 **Design Highlights**:\n- **Modern Theme**: `ttk.Style` for polished UI.\n- **File Import/Export**: Simple dialogs to load/save S-Box data.\n- **Treeview Tables**: Clean, tabular display for S-Boxes and results.\n\n#### 🔹 **Threading**:\nEnsures analysis does not freeze the GUI:\n\n```python\nanalysis_thread = threading.Thread(target=self.analyze_sbox)\nanalysis_thread.start()\n```\n\n---\n\n### 4. **Testing and Debugging**\n\n- **Functionality Testing**: Verify accuracy of all metrics with diverse S-Box inputs.\n- **GUI Testing**: Ensure all UI elements are responsive and intuitive.\n- **Error Handling**: Robust handling for invalid inputs or runtime errors.\n\n---\n\n## 📦 Installation\n\n1. **Clone the Repository**:\n\n    ```bash\n    git clone https://github.com/whdhdyt21/sbox-analyzer.git\n    cd sbox-analyzer\n    ```\n\n2. **Install Dependencies**:\n\n    ```bash\n    pip install numpy pandas openpyxl\n    ```\n\n3. **Run the Application**:\n\n    ```bash\n    cd src\n    python main.py\n    ```\n\n---\n\n## 📋 Usage\n\n1. **Import S-Box**:\n   - Click \"📥 Import S-Box from Excel\" and select a file.\n\n2. **Select Metrics**:\n   - Choose analysis metrics (e.g., Nonlinearity, SAC, etc.).\n\n3. **Analyze**:\n   - Click \"⚙️ Analyze S-Box\" to start.\n\n4. **View Results**:\n   - Results are displayed in the \"📈 Results\" section.\n\n5. **Export Results**:\n   - Save results by clicking \"💾 Export Results to Excel\".\n\n6. **Reset Application**:\n   - Use \"🔄 Reset\" to start fresh.\n\n---\n\n## 🤝 Contributing\n\nWe welcome contributions! Here's how to get involved:\n\n1. **Fork the Repository**\n2. **Create a Feature Branch**:\n\n    ```bash\n    git checkout -b new-feature\n    ```\n\n3. **Commit Changes**:\n\n    ```bash\n    git commit -m \"Add new feature\"\n    ```\n\n4. **Push Changes**:\n\n    ```bash\n    git push origin new-feature\n    ```\n\n5. **Submit a Pull Request**\n\n---\n\n## 📞 Contact\n\nQuestions? Feedback? Reach out to us:\n\n- **Email**: wahidh776@gmail.com\n- **GitHub**: [@whdhdyt21](https://github.com/whdhdyt21), [@arshandariza](https://github.com/arshandariza), [@raaapiiip](https://github.com/raaapiiip)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhdhdyt21%2Fsbox-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhdhdyt21%2Fsbox-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhdhdyt21%2Fsbox-analyzer/lists"}