Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for V8 Javascript Engine's Math.Random()? #31

Open
innsternet opened this issue Jul 4, 2015 · 5 comments
Open

Support for V8 Javascript Engine's Math.Random()? #31

innsternet opened this issue Jul 4, 2015 · 5 comments

Comments

@innsternet
Copy link

Awesome project by the way.

Would it be possible to support Javascript's Engine (V8) Math.Random() which is used by Chrome/Node.js?
(https://github.com/v8/v8-git-mirror/blob/master/src/math.js)
(http://v8.googlecode.com/svn-history/r8490/branches/bleeding_edge/src/v8.cc)

function MathRandom() {
  var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0;
  rngstate[0] = r0;
  var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0;
  rngstate[1] = r1;
  var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0;
  // Division by 0x100000000 through multiplication by reciprocal.
  return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10;
}

For example making it possible to predict the upcoming values from Math.random() on Chrome/Web Applications running NodeJs.

Thanks.

@moloch--
Copy link
Contributor

@altf4
Copy link
Owner

altf4 commented Jul 17, 2015

Nodejs is too popular to ignore, we should really have support for this. I'll try to take it up after defcon.

@altf4
Copy link
Owner

altf4 commented Aug 19, 2015

The line...

  return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10;

...bothers me because it's floating point multiplication. But I'll see what I can do to replicate it...

@innsternet
Copy link
Author

Yeah I whipped up a quick and dirty brute-forcer a while ago in C++ and had the same issue and in the end I just kept it simple and dealt with everything in integers and then did the floating point conversion in Javascript with the browser manually at the end; which wasn't ideal but I got the end result I was after.

@altf4
Copy link
Owner

altf4 commented Aug 19, 2015

Yea, that's what I'm afraid of. For untwister, we can't do offloading to another engine like a browser, so I'll just have to figure out the floating point division thing. No big deal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants