Skip to content

0xLaileb/sBurger-256

Repository files navigation

sBurger-256 Logo

sBurger-256

A custom symmetric block cipher for .NET with a 256-bit key and substitution-permutation network.

Release Downloads Last Commit .NET 10 License


πŸ“‹ Table of Contents


πŸ“– About

sBurger-256 is a custom symmetric encryption algorithm built as a .NET class library. It uses a 256-bit key and a substitution-permutation network to encrypt and decrypt data in blocks of up to 32 bytes.

The cipher derives internal transformation parameters from the key, then applies a sequence of XOR, bit-rotation, and bit-inversion operations to each byte of the data block.

sBurger-256 demo

⚠️ Note: This is an author's experimental cipher created for educational purposes. It has not been formally audited. Do not use it for protecting sensitive data in production.


✨ Features

Characteristic Value
Created 2020
Key size 256 bits (32 bytes)
Block size 8 .. 256 bits (1 .. 32 bytes)
Rounds 1 round per byte
Type Substitution-permutation network
Capability Description
Encryption Encrypts a data block (1–32 bytes) in place
Decryption Decrypts a data block (1–32 bytes) in place
GenerationSettings Derives internal cipher parameters from the key
Input validation Guards against null, wrong-length keys, and out-of-range data blocks

πŸš€ Getting Started

πŸ“Œ Prerequisites

πŸ“¦ Installation

Option 1 β€” Project Reference

Clone the repository and add a project reference:

<ProjectReference Include="path\to\src\sBurger256.csproj" />

Option 2 β€” Copy the Source File

Copy src/sBurger256.cs directly into your project.


πŸ’‘ Usage

using System.Security.Cryptography;
using System.Text;

// 1. Create a 256-bit key (e.g. from a passphrase via SHA-256).
byte[] key = SHA256.HashData(Encoding.UTF8.GetBytes("your passphrase"));

// 2. Initialize the cipher and generate settings.
var cipher = new sBurger256.sBurger256 { Key = key };
cipher.GenerationSettings();

// 3. Encrypt a 32-byte block.
byte[] data = Encoding.UTF8.GetBytes("Hello, sBurger-256 cipher test!!");  // 32 bytes
cipher.Encryption(data);
Console.WriteLine($"Ciphertext: {Convert.ToHexString(data)}");

// 4. Decrypt back.
cipher.Decryption(data);
Console.WriteLine($"Plaintext:  {Encoding.UTF8.GetString(data)}");

πŸ‘‰ See the full working demo in examples/sBurger256.Example/Program.cs.


πŸ“š API Reference

πŸ”¨ Constructor

public sBurger256()

Creates a new cipher instance. Set the Key property and call GenerationSettings() before encrypting or decrypting.

🏷️ Properties

Property Type Description
Key byte[] The 256-bit (32-byte) encryption key. Validated on set; internally copied.

πŸ“ Constants

Constant Type Value Description
KeyLength int 32 Required key length in bytes.
MaxBlockSize int 32 Maximum data block size in bytes.

βš™οΈ Methods

πŸ”§ GenerationSettings

public void GenerationSettings()

Derives internal cipher parameters from the current key. Must be called once after setting the key and before any encryption or decryption. Throws InvalidOperationException if the key has not been set.

πŸ”’ Encryption

public byte[] Encryption(byte[] data)

Encrypts the data block in place and returns the same array. Data length must be between 1 and 32 bytes. Throws ArgumentException for invalid length, InvalidOperationException if settings were not generated.

πŸ”“ Decryption

public byte[] Decryption(byte[] data)

Decrypts the data block in place and returns the same array. Data length must be between 1 and 32 bytes. Throws ArgumentException for invalid length, InvalidOperationException if settings were not generated.


πŸ§ͺ Running Tests

dotnet test

Tests are located in tests/sBurger256.Tests/ and use xUnit. They cover key validation, roundtrip encryption/decryption, determinism, boundary conditions, and wrong-key scenarios.


πŸ—οΈ Project Structure

sBurger-256/
β”œβ”€β”€ πŸ“ src/
β”‚   β”œβ”€β”€ πŸ“„ sBurger256.cs              # Library source
β”‚   └── πŸ“„ sBurger256.csproj
β”œβ”€β”€ πŸ“ tests/
β”‚   └── πŸ“ sBurger256.Tests/          # xUnit tests
β”‚       β”œβ”€β”€ πŸ“„ sBurger256Tests.cs
β”‚       └── πŸ“„ sBurger256.Tests.csproj
β”œβ”€β”€ πŸ“ examples/
β”‚   └── πŸ“ sBurger256.Example/        # Console demo app
β”‚       β”œβ”€β”€ πŸ“„ Program.cs
β”‚       └── πŸ“„ sBurger256.Example.csproj
β”œβ”€β”€ πŸ“„ Directory.Build.props           # Shared build settings
β”œβ”€β”€ πŸ“„ Directory.Packages.props        # Central package management
β”œβ”€β”€ πŸ“„ sBurger256.slnx                 # Solution file
└── πŸ“„ README.md

🀝 Contributing

Contributions are welcome! To get started:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/my-feature)
  3. ✏️ Make your changes and add tests
  4. βœ… Run dotnet test to verify everything passes
  5. πŸ“¬ Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License.

πŸ“– Star History

Star History Chart

About

πŸ” sBurger-256 - is a byte-level symmetric encryption algorithm (C#).

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages