Menu

Split any file into a keyless block and a 128-bit key - in two bitwise operations
πŸ–ΌοΈ

Split any file into a keyless block and a 128-bit key - in two bitwise operations

DEV CommunityΒ·Paul FrolΒ·6 months ago
#l4Z7M9ji
#try#python#security#block#file
Reading 0:00
15s threshold

What if you could take any file β€” a photo, a database dump, a movie β€” and split it into two parts where neither part is useful on its own? Not encryption. Not compression. Just a clean cut.

That's bitsplit . It's pure Python, zero dependencies, and the entire restore operation is a single line:

restored = ( data << count ) | indices

Enter fullscreen mode

Exit fullscreen mode

The idea

Treat the whole file as one giant integer. Slice the top 128 bits off the front. Those 128 bits become your key (a short text string). Everything else becomes your block (a binary file).

File (bytes) --> Number --> [ data: 128 bits | indices: the rest ] | | key file data file

Enter fullscreen mode

Exit fullscreen mode

To restore: shift the key left, OR with the block, write bytes. Done.

photo.jpg --> data.bin + key.txt 1.05 MB 1.05 MB 102 B

Enter fullscreen mode

Exit fullscreen mode

Why does this work? Because the 128 missing bits sit at the most significant positions of the number.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.