This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Corona's profile picture

CryptX - Symmetric Encryption Algorithm

Started by Corona, 12 April 2016 - 08:55 PM
Corona #1
Posted 12 April 2016 - 10:55 PM
Hello, CC community!

I've just recently come back to writing programs for computercraft again and thought it would be a good idea to start off simple.

The API I've made is an object-based encryption algorithm, which works symmetrically, meaning, that you use one password to de- and encrypt. I know it is neither efficient, nor uncrackable (I know someone can do this.), but it works, and that's the main point. "Quod erat demonstrantum", as romans would say.

The API has 4 methods;

--creates the object and sets an encryption password. The password is optional, as it can be set later with initialize()
function CryptX:craft( password )

--Initializes the seed and everything else to begin de/encryption
function CryptX:initialize( password )

--Encrypts a string and returns an encoded table.
function CryptX:encrypt( str )

--Decrypts the table created by encrypt() and returns the original string. Please note, that the password used for decryption must match the on used to encrypt the message.
function CryptX:decrypt( tEncr )

It can be downloaded via pastebin, but it needs another API to function; Stringmanager, also found below. Load both APIs via os.loadAPI() and you're good to go!

PS: Saving can be achieved by serializing the table. I have to streamline the whole thing a bit, a table isn't the best solution, honestly!

CryptX: http://pastebin.com/rNEUDtJf
StringManager: http://pastebin.com/U0GDqWzv
Anavrins #2
Posted 13 April 2016 - 12:32 AM
So here's my thought on this…
It's not the first time people has made ciphers using the built-in math.random function, I myself did that once, but there are few problems with it.
Mainly, it's not cryptographically secure, it uses something called linear congruential generator, which is not at all suited for crypto purposes.
In general stream-ciphers are by themselves a random number generator, which you manually XOR with your plaintext, so depending on a system dependent generator doesn't sound like a good idea.
Example another script could replace the math.random function so that it produces an even weaker sequence.
Edited on 12 April 2016 - 10:33 PM
Corona #3
Posted 13 April 2016 - 06:00 AM
A good point indeed, but as I mentioned, this thing wasn't meant to be secure, or even remotely useful, it was more of a little warm-up for the things I want to do in the future, which all (thank goodness) don't involve encryption, as I clearly am not familiar enough with cryptography to achieve a level of quality for cipher algorithms, I would be satisfied with.

I will keep in mind what you said though (: