How do I store a 256 bit variable ?

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

  • 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?

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)