How do I store a 256 bit variable ?

Get help using Construct 2

Post » Thu Oct 27, 2016 10:03 am

Anyone knows how to store a 256 bit variable in C2?
I guess I could store it using a text variable, but is a pain doing calculations with it
B
81
S
21
G
23
Posts: 515
Reputation: 18,702

Post » Thu Oct 27, 2016 6:36 pm

I think any solution will have a certain level of pain. JavaScript stores numbers as 64bit and in some of it's calculations with integers will use 32bit.
If you use JavaScript you could use a typed array of multiple 64bit numbers and then use the memory address of that with some asm.js or web assembly that can call a cpu instruction that works on 256bit numbers. However that probably isn't very cross platform.
Another option is to use a js library like this:
https://github.com/MikeMcl/bignumber.js/
But you still have to deal with numbers in a certain way.

Besides that you probably just need to use multiple numbers or text to store the number.
B
92
S
32
G
110
Posts: 5,298
Reputation: 71,507

Post » Thu Oct 27, 2016 11:51 pm

@R0J0hound Thanks for the ideas.
Well, I was only try to replicate the SHA-256 algorithm , but if I think about it I could use binary representation using text variables and do some crazy binary operations. I guess is about time to learn a proper programming language :P
B
81
S
21
G
23
Posts: 515
Reputation: 18,702

Post » Fri Oct 28, 2016 6:17 am

Looking at the pseudo code for that algorithm it looks like it's done with just 32bit variables, so there's no issue there. Beyond that you'll need to use a plugin that provides bit operations or just use js directly. But if you were to use a plugin isn't there one that does sha256 already?
B
92
S
32
G
110
Posts: 5,298
Reputation: 71,507

Post » Fri Oct 28, 2016 6:32 am

Yes, there's already a C2 plugin for that, but I don't know JavaScript that well.
Now that you mentioned, I has a second look on on the pseudocode from Wikipedia and indeed, it uses 32 bit variables, only the resulting hash is 256 bit
There are only 5 mil bitcoins left so one might dream about getting one :P
B
81
S
21
G
23
Posts: 515
Reputation: 18,702


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 30 guests