How to open an old project from 2006 with Gambas 3.11.4?

Post

Posted
Rating:
#1 (In Topic #202)
Avatar
Regular
Godzilla is in the usergroup ‘Regular’
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:

Re: [Gambas-user] Crypt/Decrypt | Gambas

Thanks for reading.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

Godzilla said

…Is Gambas code from back then not compatible with Gambas 3?…

I think there may be backwards compatibility issues between Gambas 3 >> 2 >> 1

Can you zip your project and post it here?
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
I have messed about with the code from here https://sourceforge.ne…2.camel%40linex-QL6ZhO/1/

The issues I found: -
There were lots of Var as Byte[] which need to be Var as New Byte[]
This line I changed from
RETURN m_ptab[(CLng(m_ltab[x]) + CLng(m_ltab[y])) MOD 255]
To
RETURN 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.
<IMG src="http://www.cogier.com/gambas/CryptTest.png"> </IMG>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
Godzilla is in the usergroup ‘Regular’
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:

Code

If bytOut <> Null Then
    For ix = 0 To bytOut.Count - 1
        strDecriptedText &= Chr(bytOut[ix])
    Next
Else
    strDecriptedText = "Password incorrect."
Endif

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.
Online now: No Back to the top
1 guest and 0 members have just viewed this.