A Fresh Take on Function-Based Encryption

logo

The encryption often appears to be an ancient dark art, full of heavy concepts of mathematics, solid keys, and strict protocols. But what if you can rethink the idea of ​​the “key” completely? What if the key is not a fixed point of bits, but it is alive, breathing job?

Vernamville It is an experimental encryption that explores exactly this idea. The name praises Gilbert VernamOne of the minds behind the theory of the pillow for one time. Vernamveil is written in pure Python (with an optional dependency on nature treatment) designed for developers who are curious about internal encryption work, providing fun and educational space to build intuition around encryption. The main algorithm is about 200 lines of Bethon code (except for documents, comments and empty lines) with no external dependencies other than the standard Beton libraries.

It is important to note from the beginning: I am a ML world with a zero understanding of the interior of encryption. This initial model library has been written as an enjoyable weekend project to explore the field and learn basic concepts. As a result, Vernamveil is not intended for the use of production or protection of sensitive data for the real world. It is an educational tool, experience instead of ensuring safety. You can find the full symbol on Jaytab.

Why do you work instead of keys?

Traditional symmetric zeros rely on fixed keys, fixed secrets that can be revealed, if they are broken or frequent, for weaknesses. Vernamveil is used instead job To create a dynamic key key: fx(i, seed) -> bytes.

This simple change opens several advantages:

  • There is no clear repetition: As long as the function and seeds are unpredictable, the key remains new.
  • Mathematical flexibility: You can formulate fx Jobs using creative, multi -border, or even external data sources.
  • It is possible that it has no limit: Inspired by a single -time panel, Vernamvert allows the keys as long as necessary, and avoid reusing across large data collections.

In short, instead of relying on the confidentiality of a fixed chain, Vernamvert depends on richness and the inability to predict sports behavior. And above all, it is normative; You can select yourself fx Which will be your very secret key.

Main features and fast example

Vernamveil offers a set of ideas to enhance security and teach good encryption cleanliness:

  • Customized key flow: Use any function that takes an index and seed to produce a dynamic byte. The initial function and key together is the secret key.
  • The similar process: The same function and seeds are used for encryption and decoding.
  • Justice techniques: The real pieces are lined with random noise, mixed with fake (trap) pieces, mixed on the basis of seeds.
  • Seed development: After each piece, the seeds are updated, ensuring that small input changes lead to significant differences in the output.
  • The letter authentication: The built -in check -up to Mac to detect tampering.
  • High -level composition: Adjust the size of the part, random filling, polytheistic rate, and more to experience different levels of overcoming and performance.
  • Stability: Some processes can be optional using Numpy. Python Python is also available.

Here is a quick example of the encryption of messages and the dismantling of them:

import hashlib
from vernamveil import FX, VernamVeil


def keystream_fn(i: int, seed: bytes) -> int:
    # Simple cryptographically safe fx; see repo for more examples
    hasher = hashlib.blake2b(seed)
    hasher.update(i.to_bytes(8, "big"))
    return hasher.digest()

fx = FX(keystream_fn, block_size=64, vectorise=False)


cipher = VernamVeil(fx)
seed = cipher.get_initial_seed()
encrypted, _ = cipher.encode(b"Hello!", seed)
decrypted, _ = cipher.decode(encrypted, seed)

This simple workflow actually displays many basic ideas: advanced seeds, and the use of custom fxAnd how to encrypt/decipher reversal when preparing properly.

Under the cover: How Vernamveil works

Vernamveil collects many techniques together to create an encryption that feels violent but still provides important encryption principles. Let’s go through the main steps:

1. Divide and number

First, the message is divided into formable parts (32 bytes). The real pieces are lined with random bar before and after. Between each piece, a Random It is inserted, but decisively, the same specified is encrypted at a later time, which means that its role in setting borders is hidden in the final encoded text.

This makes it very difficult to determine where the real data is.

2. Overcoming with fake pieces and mixing

Not all pieces are real. Vernamveil injection Fake That contains purely random bye. after that mix Inevitably, based on the seed of mixing and derivative chips.

This has several effects:

  • The attackers cannot easily distinguish real data from the traps.
  • Even if there are some structural patterns, they are buried deeply under the supervision.

Along with encrypted determinants, this makes rebuilding messages without the correct seeds and a very difficult job in practice.

3. XOR surrounding stream with seed development

Then the superior message by vite by means is with a key created by your custom fx job.

However, there is a decisive development: The seed develops over time. After processing each piece, the seeds are updated by fragmentation of the current seeds with just encrypted data (or deciphering them).

This development achieves two goals:

  • The effect of collapse: One byte early change from the snow message to major changes throughout production.
  • Difficulty confidentiality: The backward secrecy is preserved because each seed has evolved by dividing the previous seeds with the current regular text piece, so the current seeds do not allow derivation of any previous seeds.

The seed works like a State SeriesRefeenting frequent keys.

4. Message authentication (MAC)

Finally, if enabled, Vernamveil adds a simple form of Chective encryption:

  • Blake2B Hmac is calculated from the encrypted text.
  • The resulting mark is attached to the encrypted text.

When decoding, the Mac is examined before Decode the message. If the mark does not match, the decoder fails immediately, protecting against absurdity and certain types of attacks such as oracles.

For more information about design, features, warnings, best practices, and more technical examples, see Readme A file on the ribo.

Future trends and open ideas

Vernamveil is an early initial model, and there is a large space for experimentation and improvement. Here are some possible trends for the future:

  • Provided operations: The transformation from the pure Beton bytes to numpyand PyTorchOr TensorFlow The matrices can greatly accelerate the generation of the keys, encryption of a piece, and create random noise through interpretation. Edit: This feature was added after the initial version and increased the implementation performance.
  • Threads: The background interconnection index can prepare IO operations continuously, so that the encryption is never stopped. Edit: IO IO was added after the initial version.
  • The usefulness of the control unit: Add the connection line interface (CLI) to allow users to run Vernamveil directly from the station with training parameters. Edit: This feature was added after the initial version.
  • Go to the lower level language: Python was chosen for clarity and ease of experimentation, but moving to a faster language like rust, C ++, or even going can improve speed and dramatically expansion. Edit: I have developed an optional C extended extension to accelerate the retail processes significantly, after the initial version.
  • Improving encryption design: The basic encryption model (based on Xor, paid function) was built for educational clarity, not flexibility against advanced attacks. There are a lot of lands that are not explored in designing more powerful layers, better switches generators, and safer authentication plans. Edit: I added the creation of artificial IV seeds, turned into an encryption approval and then Mac, and the retail was replaced by HMAC and added strong fx Other examples and features, after the initial version.

If you have more ideas or proposals, do not hesitate to open a Jaithb case. I love the reasonable ideas together! And if you are an expert of encryption, I will appreciate any constructive criticism. Vernamveil was built as an educational exercise by a person outside the encryption field, so it is very likely to remain serious defects or wrong concepts. In addition, due to my limited background in encryption, some of the techniques that I used may reinvent the uninterrupted concepts. In particular, if I get to know familiar styles or standard practices that I have not mentioned properly or at all, I will be incredibly grateful if I can refer to them. Learning the appropriate terms and references would help me better understand and improve the project.

Final ideas

Vernamville It is not intended to replace dangerous encryption libraries such as AES or Chacha20. Instead, it is stadiumA way to learn, tampering, and explore concepts such as generating dynamic keys, approved encryption, seed development, and fatigue without being lost in very dense mathematics.

It indicates that encryption is not only related to the protection of secrets, but also related to Layer inability to predictand Fracture assumptionsAnd Thinking creatively Around the place of weakness you may hide.

If you are interested in how to build encryption alternatives in the real world, or just want to explore mathematics and symbol in a fun way, Vernamville It is an excellent starting point. I am looking for your comments and comments.

Leave a Reply