TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Java Puzzle: Square Root

50 点作者 crazybob大约 12 年前

20 条评论

cromwellian大约 12 年前
Consider that SecureRandom is really a facade around multiple providers that can plug in varying implementations. :)
评论 #5405062 未加载
评论 #5405116 未加载
评论 #5412267 未加载
评论 #5405392 未加载
评论 #5405049 未加载
评论 #5405337 未加载
uvdiv大约 12 年前
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 未加载
powera大约 12 年前
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 未加载
IvyMike大约 12 年前
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 未加载
somethingnew大约 12 年前
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 未加载
itsdrewmiller大约 12 年前
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?
asabil大约 12 年前
Maybe read /proc/self/maps and /proc/self/mem and try to locate the BigInteger value in the JVM heap?
tantalor大约 12 年前
I'd start by trying to create an evil subclass of BigInteger, as it is not a final class.
评论 #5405468 未加载
wheaties大约 12 年前
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 未加载
TallboyOne大约 12 年前
Can someone explain what this is asking? I don't know java
评论 #5405083 未加载
Eduard大约 12 年前
1: Pause debugging session. 2: Look into SquareRoot.n
mingpan大约 12 年前
Are they asking for a timing attack, then?
huherto大约 12 年前
I think you can create a new instance of SecureRandom() that provides the same value that we are looking for.
doctorpangloss大约 12 年前
Hint: Many pseudo-random number generators take the square of a seed value to advance to the next sequence.
mcgin大约 12 年前
Presumably something from the java.lang.instrument package will allow you to solve this
web007大约 12 年前
Subclass BigInteger, and override equals() on your subclass to "return true;"?
评论 #5405466 未加载
jlebar大约 12 年前
Use reflection to read n. Reflection lets you bypass |private|.
评论 #5405084 未加载
评论 #5405052 未加载
wisesascha大约 12 年前
is using the ASM library not a legitimate way or would that violate the rules in some way?
评论 #5409149 未加载
uribs大约 12 年前
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 未加载
martinced大约 12 年前
Is this just like String that are actually mutable on most JVM implementations out there where the underlying char[] can be accessed using reflection?