TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Java Puzzle: Square Root

50 pointsby crazybobabout 12 years ago

20 comments

cromwellianabout 12 years ago
Consider that SecureRandom is really a facade around multiple providers that can plug in varying implementations. :)
评论 #5405062 未加载
评论 #5405116 未加载
评论 #5412267 未加载
评论 #5405392 未加载
评论 #5405049 未加载
评论 #5405337 未加载
uvdivabout 12 years ago
Force a race condition on the variable `root'.<p><pre><code> if (n.divide(root).equals(root)) { </code></pre> Try to set it to 2^20001 on the first funcall and 0 on the second.
评论 #5409673 未加载
poweraabout 12 years ago
I'm not sure this is interesting. Unless I'm missing something, the question is "find what way of breaking the compartmentalization of the JVM we haven't forbidden in these English-language rules".
评论 #5405298 未加载
IvyMikeabout 12 years ago
I'm surprised nobody's given the obvious algorithm yet: while(i &#60; BigInt(2).pow(10000)) ++i;<p>Before anyone complains, this algorithm is correct and does not break any of the rules as far as I can tell. :)<p>I think the timing attack is probably what he's really looking for.<p>Edit: as mattvanhorn pointed out, answer() is void, but that's ok... changed to a "constant time" algorithm. :)
评论 #5405575 未加载
评论 #5411940 未加载
评论 #5405356 未加载
somethingnewabout 12 years ago
Someone should just modify the StackSort algorithm that was posted yesterday (made up by xkcd) to search for Square Root functions instead and run them.<p><a href="http://gkoberger.github.com/stacksort/" rel="nofollow">http://gkoberger.github.com/stacksort/</a>
评论 #5405081 未加载
itsdrewmillerabout 12 years ago
Not really a Java guy, but could you subclass BigInteger in such a way that when .divide is called and accesses root's representation of the data, that property access reflectively examines the calling expression to find out n's representation of the data, then just square roots that and sets it as its own representation before allowing the expression to evaluate? Or something along those lines, anyway?
asabilabout 12 years ago
Maybe read /proc/self/maps and /proc/self/mem and try to locate the BigInteger value in the JVM heap?
tantalorabout 12 years ago
I'd start by trying to create an evil subclass of BigInteger, as it is not a final class.
评论 #5405468 未加载
wheatiesabout 12 years ago
I hate to break it to you but "n" is not final. Hence, you can reassign any BigInteger to it. Why not just set n = 9 and the root = 3...<p>Immutability is your friend. Use it or lose it.
评论 #5405286 未加载
评论 #5405289 未加载
评论 #5405287 未加载
TallboyOneabout 12 years ago
Can someone explain what this is asking? I don't know java
评论 #5405083 未加载
Eduardabout 12 years ago
1: Pause debugging session. 2: Look into SquareRoot.n
mingpanabout 12 years ago
Are they asking for a timing attack, then?
huhertoabout 12 years ago
I think you can create a new instance of SecureRandom() that provides the same value that we are looking for.
doctorpanglossabout 12 years ago
Hint: Many pseudo-random number generators take the square of a seed value to advance to the next sequence.
mcginabout 12 years ago
Presumably something from the java.lang.instrument package will allow you to solve this
web007about 12 years ago
Subclass BigInteger, and override equals() on your subclass to "return true;"?
评论 #5405466 未加载
jlebarabout 12 years ago
Use reflection to read n. Reflection lets you bypass |private|.
评论 #5405084 未加载
评论 #5405052 未加载
wisesaschaabout 12 years ago
is using the ASM library not a legitimate way or would that violate the rules in some way?
评论 #5409149 未加载
uribsabout 12 years ago
The only possibilities seem to be a timing attack, exploiting a bug or taking advantage of an implementation that puts the dividend value in the exception when dividing by zero.<p>I'm not sure anyone will bother writing the timing attack since he apparently gives out no prize.
评论 #5405124 未加载
martincedabout 12 years ago
Is this just like String that are actually mutable on most JVM implementations out there where the underlying char[] can be accessed using reflection?