Підтримати нас на Patreon

Project SD- Sukhachev’s cipher

Author: Denys Pavlovych Sukhachev


This is a work, and the author’s right to a work is protected by international law. The author’s ownership of the work begins from the moment the work is created.

Concept:


I understand your idea of creating an innovative 3D encryption system with distributed access elements. Let’s create a prototype of such a system in Python, using the capabilities of the GPU to process 3D geometry.

“`python

import numpy as np

import numpy.random as npr

import hashlib

from cryptography.fernet import Fernet

from cryptography.hazmat.primitives import hashes

from cryptography.hazmat.primitives.asymmetric import rsa, padding

from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes

import base64

import cupy as cp # To work with the GPU

from dataclasses import dataclass

import json

@dataclass

class Point3D:

    x: float

    y: float

    z: float

    value: int

class SpatialEncryption:

    def __init__(self, space_dimensions=(100, 100, 100)):

        “””

        Initialize the spatial encryption system

        :param space_dimensions: 3D space dimensions (x, y, z)

        “””

        self.dimensions =  space_dimensions

        self.private_key =  rsa.generate_private_key(

            public_exponent=65537,

            key_size=2048

        )

        self.public_key =  self.private_key.public_key()

    def _generate_spatial_mask(self, seed):

        “””

        Generating a spatial mask based on seed

        “””

        npr.seed(seed)

        return np.random.random(*self.dimensions)

    def _data_to_points(self, data: bytes) -> list[Point3D]:

        “””

        Convert data to 3D points

        “””

        points = []

        # Use SHA-256 to create initial coordinates

        hasher = hashlib.sha256(data)

        seed =  int.from_bytes(hasher.digest()[:8], ‘big’)

        npr.seed(seed)

        # Convert each byte of data to a point

        for i, byte in enumerate(data):

            x = npr.randomint(0, self.dimensions[0])

            y = npr.randomint(0, self.dimensions[1])

            z = npr.randomint(0, self.dimensions[2])

            points.append(Point3D(x, y, z, byte))

        return points

    def _points_to_volume(self, points: list[Point3D]) -> cp.ndarray:

        “””

        Convert points to 3D volume (on GPU)

        “””

        # Create an empty volume on the GPU

        volume =  cp.zeros(self.dimensions, dtype=cp.uint8)

        # Fill the volume with points

        for point in points:

            volume[point.x, point.y, point.z] = point.value

        return volume

    def generate_access_key(self, user_id: str, permissions: list) -> str:

        “””

        Generate an access key for the user

        “””

        key_data = {

            ‘user_id’: ‘user_id’,

            ‘permissions’: permissions,

            ‘timestamp’: str(np.datetime64(‘now’))

        }

        # Encrypt the key data

        key_bytes =  json.dumps(key_data).encode()

        encrypted_key =  self.public_key.encrypt(

            key_bytes,

            padding.OAEP(

                mgf=padding.MGF1(algorithm=hashes.SHA256()),

                algorithm=hashes.SHA256(),

                label= None

            )

        )

        return base64.b64encode(encrypted_key).decode()

    def encrypt_data(self, data: bytes, access_keys: list[str]) -> dict:

        “””

        Data encryption using spatial coding

        “””

        # Convert data to points

        points =  self._data_to_points(data)

        # Create a 3D volume on the GPU

        volume =  self._points_to_volume(points)

        # Generate a unique key for this dataset

        encryption_key =  Fernet.generate_key()

        f = Fernet(encryption_key)

        # Encrypting the volume

        encrypted_volume =  f.encrypt(cp.asnumpy(volume).tobytes())

        # Encrypt the encryption key for each recipient

        encrypted_keys = {}

        for access_key in access_keys:

            key_data = base64.b64decode(access_key)

            # Decrypt the access key data

            decrypted_key_data =  self.private_key.decrypt(

                key_data,

                padding.OAEP(

                    mgf=padding.MGF1(algorithm=hashes.SHA256()),

                    algorithm=hashes.SHA256(),

                    label= None

                )

            )

            key_info =  json.loads(decrypted_key_data)

            # Encrypt the encryption key for this user

            encrypted_keys[key_info[‘user_id’]] = self.public_key.encrypt(

                encryption_key,

                padding.OAEP(

                    mgf=padding.MGF1(algorithm=hashes.SHA256()),

                    algorithm=hashes.SHA256(),

                    label= None

                )

            )

        return {

            ‘encrypted_volume’: encrypted_volume,

            ‘encrypted_keys’: encrypted_keys

        }

    def decrypt_data(self, encrypted_data: dict, access_key: str) -> bytes:

        “””

        Decrypting data using an access key

        “””

        # Decrypt the access key

        key_data = base64.b64decode(access_key)

        decrypted_key_data =  self.private_key.decrypt(

            key_data,

            padding.OAEP(

                mgf=padding.MGF1(algorithm=hashes.SHA256()),

                algorithm=hashes.SHA256(),

                label= None

            )

        )

        key_info =  json.loads(decrypted_key_data)

        # Get the encryption key for this user

        if key_info[‘user_id’] is not in encrypted_data[‘encrypted_keys’]:

            raise ValueError(“You do not have access to this data”)

        encryption_key =  self.private_key.decrypt(

            encrypted_data[‘encrypted_keys’][key_info[‘user_id’]],

            padding.OAEP(

                mgf=padding.MGF1(algorithm=hashes.SHA256()),

                algorithm=hashes.SHA256(),

                label= None

            )

        )

        # Deciphering the volume

        f = Fernet(encryption_key)

        volume_data =  f.decrypt(encrypted_data[‘encrypted_volume’])

        volume =  np.frombuffer(volume_data, dtype=np.uint8).reshape(self.dimensions)

        # Convert back to bytes

        return volume.tobytes()

“`

Let’s take a look at how this system works:

1. Spatial coding:

   – Data is transformed into a set of 3D points in a virtual space

   – Each point has coordinates (x, y, z) and a value

   – Utilizes GPU for efficient processing of 3D space

2. Access system:

   – Each user receives a unique access key

   – Keys contain information about permissions and access levels

   – Asymmetric encryption is used to protect keys

3. 3. End-to-end encryption:

   – Full end-to-end encryption is implemented

   – Data is encrypted at the level of 3D space

   – Additionally, cryptographic encryption is used

Here’s an example of how to use it:

“`python

# Create an encryption system

encryption_system =  SpatialEncryption()

# Generate access keys for users

user1_key = encryption_system.generate_access_key(“user1”, [“read”, “write”])

user2_key = encryption_system.generate_access_key(“user2”, [“read”])

# Encrypting data

data = “Secret scientific data”.encode()

encrypted_data =  encryption_system.encrypt_data(data, [user1_key, user2_key])

# Decrypt data using the user’s key

decrypted_data =  encryption_system.decrypt_data(encrypted_data, user1_key)

“`

The system supports:

1. 1. Multilevel access to data

2. Spatial encryption on the GPU

3. Cryptographic protection of keys

4. 4. End-to-end data encryption

Останні данні щодо наших досліджень: