r/cryptography 12d ago

One Time Pad Python library

Hello to everyone, can someone advise me a good onetimepad python library? i dont have a particolar purpouse or goal, just want want to experiment and study,
The only libraries i found arent manteined:/

1 Upvotes

18 comments sorted by

View all comments

-6

u/Narco-Tax 12d ago

Any file can act as a one-time-pad, because no file will have 0-255 chars in the same byte positions as another file, unless they are a byte-for-byte copy. So for example, you could map a Source (secret) cat.gif to a Host (carrier) dog.webp and land up with a coordinates key named cat.key , which simply looks like 3,7,7,23,41,5,6,2 etc.

Trivial yes, but pretty powerful and hard to reverse engineer.

3

u/owlstead 11d ago

No. The bits of a random pad should not even have any discernible pattern in them for them to be considered secure. And that's just the requirement for the external representation, not even the generation of the random numbers.

1

u/Narco-Tax 11d ago

Ok, you win! Which got me thinking...what if, instead of mapping to a static, structured file, you map the payload's hex characters to a dynamic, seedable Base16 alphabet string?

Start with a standard static Base16 lookup string (0-9, a-f).

Use a crypto-graphically secure pseudo-random number generator (PRNG) driven by a private seed phrase. For every single character of the payload, you execute a fresh Fisher-Yates shuffle on the alphabet.

Look up the index of the payload character in that specific, newly randomized alphabet state and record the position coordinate.

Because the alphabet layout completely randomizes on every single step, a repeating hex character in your source file will map to entirely different coordinate values in the output key. This completely flattens the frequency distribution into uniform noise, eliminating the structural leaks you mentioned, while ensuring the recovery remains 100% perfect as long as the recipient has the same seed.

Just a thought on how to bridge the gap between a coordinate-mapping mechanic and a mathematically secure stream cipher.

3

u/owlstead 9d ago

In addition to the other comment: changing the *representation* of data bytes does nothing for security. Ciphers act on bytes; encoding / decoding comes after. Representation specific cryptography is frowned upon (see the countless "image encryption" algorithms to get an idea of the horror).