计算困难的[JavaScript]问题?

发布于 2024-11-19 16:33:01 字数 279 浏览 2 评论 0原文

我需要一个计算困难的问题(在任何语言中),但我可以轻松地用 JavaScript 实现。我正在尝试进行类似验证码的测试,以防止黑客机械地访问我的页面。

是的,我知道他可以使用Rhino或其他一些JS引擎并做到这一点——这就是为什么我希望它的计算成本很高,所以他需要几个小时来设置他的机器每次访问都需要几秒钟的时间来伪造。

我想在后端获取一堆大素数,然后发送其中两个素数的乘积,并要求网页将其分解,但如果有人有更好的想法,我会洗耳恭听。另外,有人有一个很好的库来进行因式分解吗?

I need a problem that is computationally difficult (in any language), that I can easily implement in JavaScript. I'm trying to do a CAPTCHA-like test to make it unlikely that hacker is accessing my page mechanically.

Yes, I know that he could use Rhino or some other JS engine and do it -- that's why I want it to be computationally expensive, so it takes him a few hours to set up and his machine a few seconds to fake each access.

I'm think getting a bunch of large primes on the back end and sending over the product of two of them and demand that web-page factor it, but if anybody has a better idea, I'm all ears. Also, does anybody have a good library for doing that factoring thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

四叶草在未来唯美盛开 2024-11-26 16:33:01

您可以使用与比特币相同的方法,即。反转安全哈希。

这里解释一下:
http://www.tomshardware.com/reviews/bitcoin -mining-make-money,3514-3.html

比特币源码
https://github.com/bitcoin/bitcoin

You can use the same method as bitcoin, ie. reversing a secure hash.

Explained here:
http://www.tomshardware.com/reviews/bitcoin-mining-make-money,3514-3.html

Bitcoin source
https://github.com/bitcoin/bitcoin

霓裳挽歌倾城醉 2024-11-26 16:33:01

您可以实现标准验证码并在客户端进行更多检查。例如,在验证码输入文本上添加一个事件侦听器以侦听按键按下/按键按下事件并异或键码并将其与验证码一起发送。在名为电子邮件的表单中添加隐藏的输入文本或您在每个表单上找到的内容。机器人会自动填充这些内容。如果您获得 post['email'] 的值,那么它就是一个机器人,因为用户不会看到它。您还可以在完全不相关的 JavaScript 中添加一段代码,该代码会自动在表单中添加验证所需的字段。所以...验证码没有验证码,您仍然可以增强机器人保护客户端,而无需计算困难的过程。

you can implement a standard captcha and make some more checking on the client side. for exaample, add a event listener on the captcha input text to listen for key down/key up events and xor the keycodes and send them along with the captcha. add a hidden input text in the form named email or something you find on every form. robots fill those up automatically. and if you get a value for post['email'] then it's a robot because the user won't see that. also you can have a piece of code in a totally unrelated javascript that automatically adds a field in the form that is required to validate. so...captcha no captcha, you can still enhance the robot protection client side without computation difficult processes.

牵强ㄟ 2024-11-26 16:33:01

问题在于,如果已知它是 NP-Hard,那么在非平凡的实例上,人类要解决它也将是一件令人头疼的事情。视觉/听觉验证码很酷,因为它们给人们带来了帮助……我们有非常复杂的感觉器官来处理这些事情,而计算机不太擅长(尽管它们一直在变得更好!) )。

因此,你可能最好想出一件人们可以轻松完成但机器不太擅长的独特事情。例如,给出一些简单的黑白图片并询问用户哪一张不属于,或者展示一些食物的图片并询问您可以用它们制作什么样的食谱。

The problem with this is that if it is known to be NP-Hard, it's going to be a pain in the rear for human beings to solve, as well, on non-trivial instances. Visual/auditory captchas are kind of cool in that they give people a leg up... we have very sophisticated sensory organs for processing these kinds of things, and computers are not too good at it (though they are getting better all the time!).

As such, you're probably better off coming up with a unique thing that people can do very easily, but that machines are not too good at. For instance, give some simple black and white pictures and ask the user which one doesn't belong, or show some pictures of foods and ask what kind of recipe you could make with them.

故事还在继续 2024-11-26 16:33:01

巧妙的方法。每当需要单向复杂性时,我就会想到哈希。只需对用户帐户的某些方面(不敏感)进行哈希处理,然后将哈希值发送给客户端。您可能需要截断/填充字符串以获得所需的复杂性级别。这并不是为了保护帐户,因此 md5 或任何其他哈希算法都可以。

以下是一些您可能能够使用的示例代码为客户端发挥杠杆作用。

Clever approach. Whenever one-way complexity is needed it makes me think of a hash. Simply hash some aspect of their user account (not anything sensitive) and send the hash to the client. You would want to truncate/pad the string to get your desired complexity level. This isn't to secure an account so md5 or any other hashing algorithm would be fine.

Here is some sample code that you might be able to leverage for the client side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文