[Plugin][Work in progress]MD5 Encryption

Discussion and feedback on Construct 2

Post » Sun Jul 31, 2011 9:47 pm

This is a work in progress, the current plugin is broken.
http://dl.dropbox.com/u/36472942/construct/plugin/wip/md5_0.e.zip

I've been working on turning a JS implementation of the MD5 algorithm into a plugin.
Basicly, it is an expression that allows you to encrypt the data you feed it with into hexadecimal MD5.
I've had a previous version that worked. (You might try it and use it if you want)

As the implementation of the algorithm has several output formats (hexa, base64 and even allows different types of encryption in the spectrum of the same functions use) I'm working on allowing the user to choose between them.

At the moment I'm stuck, as I've been adding properties to my object. And now, in the runtime, firebug tells me that "this.properties" isn't defined, blocking the whole process.
Well, it is in my edittime.js though.
(My test project is an object MD5 and an object text. On startup of layout, I set Text.text to MD5.Encrypt("Hello world !").)

I've used the structure/code from the plugin text to guide me. I've also looked in about all of the plugins code, and it seems to me they are all following the same pattern.
Right now, I can't seem to find what's wrong. I'll look over it later (and/or tommorrow) but if in the mean time the community can bring me an answer i'll be more than happy ^^

I'm still new to JS, and mainly learning it by going through C2's plugins and behaviors folders ^^ (looking a bit over jquery's documentation for future plugins too)

Edit: I'll favor the occasion to suggest an option in C2 that allows to reload/rehash the plugins and behaviors (if it is possible). As of now, on any change on my plugin, I have to quit and launch again the editor, and set up my test project (save/load can't really work as any change on the plugins makes old saves incompatible). Doable, but tedious. If it can be added harmlessly, I'll be thankful.Kyatric2011-07-31 21:51:36
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Sun Jul 31, 2011 9:56 pm

The property name accessed in runtime.js has to exactly match the property name in edittime.js. I noticed you have
"Hex output format" in edittime.js and
"Hexadecimal output format" in runtime.js,
so at runtime you'll get a "property does not exist"/"property is undefined" error. If you change them to match does that fix it?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Jul 31, 2011 10:00 pm

(Also, you can close the project and reopen and javascript files will be refreshed, it's a bit quicker than a full reload. Alternatively I made a registry key you can set:
HKEY_CURRENT_USER\Software\Scirra\Construct2\html5 - add a new DWORD value 'devmode' (without quotes) - set its value to 1.
Once that's set the scripts should be reloaded each time you hit run.)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Jul 31, 2011 10:16 pm

[QUOTE=Ashley] The property name accessed in runtime.js has to exactly match the property name in edittime.js. I noticed you have
"Hex output format" in edittime.js and
"Hexadecimal output format" in runtime.js,
so at runtime you'll get a "property does not exist"/"property is undefined" error. If you change them to match does that fix it?[/QUOTE]

No it doesn't. The name change was a test I didn't finished, as I was wondering if maybe the length of the properties entered in play.
I just tried with "Hex output format" for both, and still "this.properties is undefined Line 50". It's the whole properties array which is absent, not that single property.

EDIT: I even tried "Hexoutput" as name of the property and it still didn't work.
So it's not a length thing. I'll keep on looking.Kyatric2011-07-31 22:57:51
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Sun Jul 31, 2011 11:13 pm

Oops, on further inspection it looks like an oversight in the SDK. 'singleglobal' objects can't have properties right now. You'll have to work around it with actions to set the settings.

BTW I think MD5 is better described as a hash than encryption - I think encryption is supposed to be reversible.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Jul 31, 2011 11:38 pm

[QUOTE=Ashley]
BTW I think MD5 is better described as a hash than encryption - I think encryption is supposed to be reversible.[/QUOTE]

Yes, please call this Hash as it is easily reversible. You don't want to give folks the wrong idea about the plugin's purpose. The goal of the hash algorithm (MD5) is to verify that the data hasn't been changed.

Also, why not do SHA-1 if you are going to do a cryptographic hash algorithm.. MD5 has already been broken.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sun Jul 31, 2011 11:55 pm

[QUOTE=Ashley] Oops, on further inspection it looks like an oversight in the SDK. 'singleglobal' objects can't have properties right now. You'll have to work around it with actions to set the settings.[/quote]

As those properties are not vital to the user at this stade of the plugin, I'll comment the lines refering to the properties (as it seems to me the code should work once the properties are part of the 'singleglobal' flaged objects.)
I'll be uncommenting them when the changelog of a future build will indicate me to ;)


[QUOTE=Ashley]BTW I think MD5 is better described as a hash than encryption - I think encryption is supposed to be reversible.[/QUOTE]

You're right, thanks for the notice.


JS is a fun language to work with, and the design of C2's extensions make them quite forward/"simple" to make. (cheers on the smart comments)

It's thrilling.


[QUOTE=scidave]
Yes, please call this Hash as it is easily reversible. You don't want to give folks the wrong idea about the plugin's purpose. The goal of the hash algorithm (MD5) is to verify that the data hasn't been changed.

Also, why not do SHA-1 if you are going to do a cryptographic hash algorithm.. MD5 has already been broken. [/QUOTE]
Category name changed to Hash, and reference to cryptography removed.
I intend to implement SHA-1 and SHA-256 in the same plugin. I'll first have to get the md5 different outputs to correctly work and then implement the other.

It should end as a multi-algorithms Hash plugin.Kyatric2011-08-01 00:28:39
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Mon Aug 01, 2011 12:34 am

[QUOTE=Kyatric]I intend to implement SHA-1 and SHA-256 in the same plugin. I'll first have to get the md5 different outputs to correctly work and then implement the other.

It should end as a multi-algorithms Hash plugin.[/QUOTE]

Just a heads up: the plugin ID in edittime.js GetPluginSettings() is currently "MD5". You can change all the other settings at any time, but the ID is the string C2 uses to identify your plugin. If you change the ID from "MD5" to something else, all existing projects using the plugin will no longer load, since C2 will consider it a different plugin.

Basically, try to choose the correct ID string when starting a plugin, and then never change it, or you might end up breaking lots of projects. Since the only public version is broken, I guess now is a good time to set it to "Hash" or whatever :)Ashley2011-08-01 00:35:16
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Wed Aug 03, 2011 12:40 pm

New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795


Return to Construct 2 General

Who is online

Users browsing this forum: BBaller1337, Lancifer, Pehesse and 14 guests