AS3的BigInteger返回一个不正确的答案 [英] As3 BigInteger returns an Incorrect Answer

查看:150
本文介绍了AS3的BigInteger返回一个不正确的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在Flash中的RSA加密程序。我看着与大数字的工作,发现在加密包中的BigInteger变种类型。我开始玩弄BigIntegers但我的输出是永远正确的答案。例如下面的code将输出5911时,答案应该是9409.关于此错误的任何投入将是巨大的。

  VAR温度:BigInteger的=新的BigInteger(字符串(97));
临时= temp.pow(2);
跟踪(temp.toString());

输出= 5911
 

解决方案

我不知道你指的是,我该加密包虽然当时的 as3crypto ,但我不记得这是有一个 POW 方法,该方法具有签名implementions。但无论哪种方式,你永远要记住什么基础你正在处理的,哪些库是专为。

(97 16 2 = 5911 16

您正在处理十六进制,不是小数,数字。

想那怪胎,是别致的T恤,上面写着有10种人,那些了解二进制和那些不。在这种情况下,10被假定为10 <子> 2 。这相当于2 10 。不合格的基地几乎都毁了每个人的一天。

I am trying to implement a RSA encryption program in flash. I looked into working with Big Numbers and found the BigInteger var type in the Crypto package. I started playing around with BigIntegers but my outputs are never the correct answer. For example the below code will output 5911 when the answer should be 9409. Any input about this error would be great.

var temp:BigInteger = new BigInteger(String(97));
temp = temp.pow(2);
trace(temp.toString());

Output = 5911

解决方案

I'm not sure which crypto package you are referring to, I though it was as3crypto but I don't remember it's implementions having a pow method that has that signature. But either way, you always have to remember what base you are dealing with and what the library was designed for.

(9716)2 = 591116

You are dealing with hex, not decimal, numbers.

Think of that geek-is-chic tshirt that says "There are 10 kinds of people. Those that understand binary and those that don't". In that case "10" is assumed to be 102. Which equals 210. Unqualified bases almost always ruin everybodys day.

这篇关于AS3的BigInteger返回一个不正确的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆