-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashingPage.html
87 lines (74 loc) · 2.49 KB
/
HashingPage.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE HTML>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://peterolson.github.com/BigInteger.js/BigInteger.min.js"></script>
<script src="http://peterolson.github.com/BigRational.js/BigInt_BigRat.min.js"></script>
</head>
<body>
<p>Header</p>
<p>Footer</p>
<FORM>
<INPUT ID="Box1" TYPE="Text">
<P>
<INPUT ID="Box2" TYPE="Text">
<P>
<INPUT ID="Box3" TYPE="Text">
<P>
<INPUT ID="TheButton" TYPE="Button" Value="Recover">
</FORM>
<script>
var zero = bigRat();
var threeFourths = bigRat(0.75);
var fiveHalves = bigRat("5/2");
$("#TheButton").click(function(){
$("#Box1").val(fGenerateBigLimitedInt(1, 4));
});
// Generate a large integer.
var fGenerateBigInt = function(pSize){
var lclGeneratedNumber = bigInt();
var lclRPrecision = pSize;
var lclRArray = new Uint32Array(lclRPrecision);
window.crypto.getRandomValues(lclRArray);
for (var i = 0; i < lclRArray.length; i++){
lclGeneratedNumber = lclGeneratedNumber.add(bigInt(2).pow(32).pow(i).multiply(bigInt(lclRArray[i])));
}
return lclGeneratedNumber;
};
var fGenerateBigLimitedInt = function(pLowerLimit, pUpperLimit){
// Returns x: pLowerLimit <= x < pUpperLimit
var lclSizeOfGenerator = 0;
var lclRange = bigInt(pUpperLimit - pLowerLimit);
while (bigInt(2).pow(32 * lclSizeOfGenerator).lesserOrEquals(lclRange)){
lclSizeOfGenerator++;
};
console.log(lclSizeOfGenerator)
return fGenerateBigInt(lclSizeOfGenerator).mod(lclRange).add(pLowerLimit);
};
var fMillerRabinIsComposite = function(pTestNumber, pNumberOfTests){
// The miller Rabin Primality Test.
//if (pTestNumber < 3){
// console.log("Warning: " + pTestNumber + " is not 3 or greater in fMillerRabinIsComposite Test.");
//}
var lclPARs = 0;
var lclPARd = pTestNumber.minus(1);
while (lclTempNumber.mod(2).equals(0)){
lclPARs++;
lclPARd = lclPARd.divide(2);
};
for (var i = 0; i < pNumberOfTests; i++){
var lclRandomNumber = fGenerateBigLimitedInt(2, pTestNumber - 2);
var lclPARx = lclRandomNumber.pow(lclPARd).mod(pTestNumber);
if (lclPARx.equals(1) || lclPARx.equals(pTestNumber.minus(1))){
} else {
for (var j = 0; j < lclPARs - 1; j++){
lclPARx = lclPARx.square().mod(pTestNumber);
if (lclPARx.square
}
}
}
return false;
}
</script>
</body>
</html>