-
Notifications
You must be signed in to change notification settings - Fork 0
/
primeString.html
193 lines (168 loc) · 4.33 KB
/
primeString.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<style>
label {
width: 250px;
display: inline-block;
padding-right: 5px;
}
</style>
<script src='https://cdn.jsdelivr.net/npm/bignumber.js@9.1.0/bignumber.min.js'></script>
<script>
"use strict";
function isPrime(n) {
var sqrtn = Math.sqrt(n);
for (var i = 2; i <= sqrtn; i++)
if (n % i === 0) return false;
return true;
}
// https://github.com/MikeMcl/bignumber.js
function solve(form){
let bigint0 = 1n;
let bigint1 = 1n;
let number = 1;
let number2 = 1;
let primestringlist = "";
let primestring0 = "";
let primestring1 = "";
var zero="0";
var one="1";
var bits0="";
var bits1="";
var hex="";
let primeNum = eval(form.P.value);
while (number <= primeNum) {
if (isPrime(number2) && number2 >= 2) {
bits0=zero.repeat(number2);
bits1=one.repeat(number2);
primestringlist += number2;
primestringlist += " ";
primestring0 += bits0;
primestring0 += one;
primestring1 += bits1;
primestring1 += zero;
number++;
}
number2++;
}
form.PL.value = primestringlist;
bigint0 = new BigNumber(primestring0, 2);
form.PS0.value = primestring0;
form.P0.value = bigint0.toFixed(0);
bigint1 = new BigNumber(primestring1, 2);
form.PS1.value = primestring1;
form.P1.value = bigint1.toFixed(0);
}
function convertToPrimestring(form){
let bigint = 1n;
let primestring = form.BIGINT.value;
let base = form.BASE.value;
var baseInt = parseInt(base, 10);
const binaryRepresentation = BigInt(primestring).toString(baseInt);
form.PS.value = binaryRepresentation;
}
function reset(form) {}
</script>
<html>
<body class=main>
<form name="form">
<div align="center">
<h1>Bigint Primestring Calculator</h1>
<center>
<table border="0" width="auto" cellspacing="3" cellpadding="3">
<tr class=cel>
</tr>
<tr>
<td class="label"> Prime Numbers</td>
<td class="cel">
<input TYPE="text" NAME="P" SIZE="10" VALUE="10">
</td>
</tr>
<tr>
<td class="label"> Primes</td>
<td class="cel">
<textarea id="PL" rows="4" cols="100"></textarea>
</td>
</tr>
<tr>
<td class="label"> Primestring Bin 0</td>
<td class="cel">
<textarea id="PS0" rows="4" cols="100"></textarea>
</td>
</tr>
<tr>
<td class="label"> Primestring Bin 1</td>
<td class="cel">
<textarea id="PS1" rows="4" cols="100"></textarea>
</td>
</tr>
<tr>
<td class="label"> Primestring Hex</td>
<td class="cel">
<textarea id="PSH" rows="4" cols="100"></textarea>
</td>
</tr>
<tr>
<td class="label"> Bigint Primestring 0</td>
<td class="cel">
<textarea id="P0" rows="4" cols="100"></textarea>
</td>
</tr>
<tr>
<td class="label"> Bigint Primestring 1</td>
<td class="cel">
<textarea id="P1" rows="4" cols="100"></textarea>
</td>
</tr>
<tr>
<td class="label"> Bigint</td>
<td class="cel"><textarea id="B" rows="4" cols="100"></textarea></td>
</tr>
<tr>
<td class="cel"></td>
<td colspan="2" class="cel">
<input type="button" value="Solve" onClick="solve(form)">
<input type="button" value="Reset" onClick="reset(form)">
</td>
</tr>
</table>
</center>
</div>
</form>
<form name="form2">
<div align="center">
<h1>Bigint To Primestring Calculator</h1>
<center>
<table border="0" width="auto" cellspacing="3" cellpadding="3">
<tr class=cel>
</tr>
<tr>
<td class="label"> Primestring Bigint</td>
<td class="cel">
<textarea id="BIGINT" rows="4" cols="100">604256080671722940072465926032430565687294</textarea>
</td>
</tr>
<tr>
<td class="label"> Primestring Base</td>
<td class="cel">
<textarea id="BASE" rows="4" cols="100">2</textarea>
</td>
</tr>
<tr>
<td class="label"> Primestring</td>
<td class="cel">
<textarea id="PS" rows="4" cols="100">0</textarea>
</td>
</tr>
<tr>
<td class="cel"></td>
<td colspan="2" class="cel">
<input type="button" value="Solve" onClick="convertToPrimestring(form2)">
<input type="button" value="Reset" onClick="reset(form2)">
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>