I was researching encryption and decryption in Gambas. Both functions don't appear to exist in Gambas.

I found an old project from 2006 in the Gambas mailing list archives, where old VB source code for AES encryption/decryption was "Gambasized" and is said to work, according to the message. This would be perfect for me to play around with.

The problem is, I can't get Gambas 3.11.4 to recognize and open this old project. I created a new project, pasted the contents of CRijndael.class into a new class. Attempted to init and call it from within the program, using the contents of FrmMain.class as a guide. But I get nothing but syntax errors from CRijndael.class. Is Gambas code from back then not compatible with Gambas 3?

The project is found as an attachment (gambasCrypt.tar.gz) to this message:

The issues I found: -
There were lots of Var as Byte[] which need to be Var as New Byte[]
This line I changed fromRETURN m_ptab[(CLng(m_ltab[x]) + CLng(m_ltab[y])) MOD 255]
ToRETURN m_ptab[(CLong(m_ltab[x]) + CLong(m_ltab[y])) MOD 255]
The Form is in a mess. I have created something similar.

The code I have modified does encrypt but I have no idea how to decrypt but hopefully this is a start.

cogier, you've done it! Your project does encrypt and decrypt without any further modification.

Playing around with it, I discovered the way to decrypt is to 1) encrypt some text 2) erase the contents of txtClear.Text, while leaving the other fields unchanged 3) click the decrypt button, which outputs the decrypted text into txtClear.Text.

TextBox1 seems to serve no purpose other than that of a label. It came in handy to check the length of the encrypted text, out of curiosity (avoiding the Print command). Turns out the minimum length of the encrypted text is 64 characters. However, if the unencrypted text length > 28 then the encrypted length grows to 128, then 192, etc. In my tests, the password length seems to have no effect on the length of the encrypted text.

I noticed that attempting to decrypt with an incorrect password gives a NULL error in CRijndael.class. To assist anyone in the future who finds use for this code, I modified CRijndael.class in the DecryptString section, to avoid this error:

In the original post from 2006, the author mentioned of the speed of this code was an issue. In my tests, both encryption and decryption of even long strings of text seems instantaneous in the Gambas IDE. Even below the measurable limits of a timer. I attribute this to modern hardware, modern Linux, and a much more optimized version of Gambas. No doubt, performing these functions on something huge like a file of several mB would undoubtedly begin to show a measurable lag.

cogier, thank you once again for lending your knowledge to solve a problem I could have never figured out.