Adding comments would be hard, because I played around with encrypting until it was safe. So i try to describe what the API does.
Every letter has a Byte. ComputerCraft uses the
ASCII-Table. For example the P is byte 80. The difference between Computercraft and real Computers is, that CC-PCs can't handle letters which aren't printable. (like byte 27, which is the ESC-Key) It just replaces them with a ? which is byte 63. If I add the bytevalue of the key to the bytevalue of the letter, I must look that the result stays between 32 and 126. So I played around with the bytes to keep them between 32 & 126.
The "enc"-Function takes the key, converts it into bytes, subtracts 31 from it and puts every byte into an Array.
Then every Letter of the String gets converted to bytes. These are added to one byte of the key. If the last letter of the key was used, it begins again with the first letter. If the result is bigger than 126 it gets substracted by 126 and then added by 31. So it stays in the range of the printable letters. The result gets returned to the "encrypt"-Function.
The "encrypt"-Function just messes around with the key and the string to make the encryption safe. Before i did this, the encrypted String was a bit readable even with a key with one wrong letter. I'm to lazy to explain it more accurate.
The "decrypt" and the "dec"-Function is basically the same than the encryption, but backwards.
Wow, just written so much… Sorry if i have written crap, english is not my native language. Hope I helped you.
@TheOriginalBIT – Explaining the encryption doesn't make it less save. You need to bruteforce the string with every possible password. And even then you need an algorithm or a person which observs the bruteforce to distinguish an successfully decrypted string from crap, because the decryption doesn't tell you an error, it just returns something what could be right (or wrong).