Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Python Diary: Encryption experiment in Python

$
0
0

I recently created a toy encryption tool using pure Python, and it's dead simple to implement and use. It is slow in CPython, a bit faster in Cython, and runs nicely in a compiled language like ObjectPascal.

I created this as a way to better understand how encryption works and to allow others who don't understand cryptography to have an easy to read and learn example of the utter basics of encryption. This code can be easily expanded to further strengthen it. It uses eXclusive OR to toggle bits which is what does the actual encryption here. It is a stream cipher, so the key and input can be variable in length. The encryption works by using a custom table, or master key as it is labeled in the code, along with an actual password/passphrase. I'd highly recommend passing an SHA512 digest hash of a password.

My initial idea was to create a Crypto Virtual Machine, where each byte in the password/passphrase would map to a virtual op code in the VM. This op code would then do something to the current byte to be encrypted, so effectively the password is a bytecode string for this VM which tells the VM how to encrypt and decrypt the clear-text or otherwise data to be encrypted. This may make encryption slow, as a VM needs to parse through each and every byte and do something to it, and it needs to be reversible using the same bytecode. Essentially you would need an encryption VM, and a decryption VM. The encryption VM would perform the encryption of the bytes or blocks, and the decryption VM would perform the decryption. So rather than a set algorithm, each byte in your key works with a VM to perform almost random encryption making it almost impossible to decrypt without knowing the bytecode the VM needs to decrypt it.

This is only a theory on how more advanced computers with faster processing power could implement encryption, and technically a dedicated microcontroller or processor could be used to implement what the bytecodes do in the hardware level. I do still plan on making an example Virtual Machine like this to play around with the idea. For now, you can check out the encryption project I talked about above here on my KCrypt source code.


Viewing all articles
Browse latest Browse all 22462

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>