我正在编写一个脚本,需要对非常大的整数(加密算法)执行算术运算,因此我尝试使用外部库(https://github.com/peterolson/BigInteger.js/tree/master)。但是,当我将src属性添加到脚本标记时,即使我的buttonClick()函数已明确定义,我也会收到错误消息“未捕获的ReferenceError:buttonClick未定义”。我需要使用这个库,我不知道该怎么做。
<script type="text/javascript" src="http://peterolson.github.com/BigInteger.js/BigInteger.min.js">
...
<button type="button" onclick="buttonClick()">Encrypt</button>
...
function buttonClick(){
plaintext = document.getElementById("plaintext").value;
plaintextLength = plaintext.length;
plaintextNum = [];
plaintextNumString = "";
for(var i = 0; i < plaintextLength; i++){
plaintextNum[i] = plaintext.charCodeAt(i);
plaintextNumString += plaintextNum[i];
}
plaintextNumInt = bigInt(parseInt(plaintextNumString));
//ciphertextNumInt = bigInt((Math.pow(plaintextNumInt, e))%n);
ciphertextNumInt = plaintextNumInt.modPow(e, n);
console.log(plaintextNumInt + " " + plaintextNum[2] + " " + ciphertextNumInt + " " + n + " " + plaintext);
document.getElementById("ciphertext").innerHTML = ciphertextNumInt;
}