forked from RandstormBTC/randstorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecureRandomGenerator.html
186 lines (156 loc) · 5.91 KB
/
SecureRandomGenerator.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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,700&display=swap">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bitcoin Key Generation</title>
<style>
body {
font-family: 'Poppins', sans-serif; /* Modern font */
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
background-color: #121212; /* Almost black background */
margin: 0;
padding: 20px;
justify-content: flex-start; /* Align content to the top */
font-size: 16px;
color: #ecf0f1; /* Light text for contrast */
}
button {
background-color: #3498db; /* Blue color */
color: white;
padding: 15px 30px;
font-size: 18px;
cursor: pointer;
border: none;
border-radius: 5px;
margin-bottom: 20px;
transition: background-color 0.3s ease;
outline: none; /* Remove button outline on click */
}
button:hover {
background-color: #2980b9; /* Darker blue on hover */
}
}</style>
<script src="https://raw.githubusercontent.com/pointbiz/bitcoinjs-lib/9b2f94a028a7bc9bed94e0722563e9ff1d8e8db8/src/eckey.js"></script>
</head>
<body><h1> Math.random Generator</h1>
<div id="browserInfo"></div>
<div id="randomValues"></div>
<div id="highLowBits"></div>
<p id="keys"></p>
<button onclick="generateKeys()">Generate Math.random Values</button>
<script>
function SecureRandom3() {
var SEED_TIME_VALUE = 1294200190000;
this.pool = null;
this.pptr = 0;
this.poolSize = 256;
this.state = null; // Added state variable
this.seedTime = function () {
this.seedInt(SEED_TIME_VALUE);
};
this.seedInt = function (x) {
this.pool[this.pptr++] ^= x & 255;
this.pool[this.pptr++] ^= (x >> 8) & 255;
this.pool[this.pptr++] ^= (x >> 16) & 255;
this.pool[this.pptr++] ^= (x >> 24) & 255;
if (this.pptr >= this.poolSize) this.pptr -= this.poolSize;
};
this.getByte = function () {
if (this.state == null) {
this.seedTime();
this.state = this.ArcFour();
this.state.init(this.pool);
for (this.pptr = 0; this.pptr < this.pool.length; ++this.pptr)
this.pool[this.pptr] = 0;
this.pptr = 0;
}
return this.state.next();
};
// Initialize the pool
if (this.pool == null) {
this.pool = new Array(this.poolSize);
this.pptr = 0;
var t;
while (this.pptr < this.poolSize) {
t = Math.floor(65536 * Math.random());
this.pool[this.pptr++] = t >>> 8;
this.pool[this.pptr++] = t & 255;
}
this.pptr = 0;
this.seedTime();
}
}
SecureRandom3.prototype.ArcFour = function () {
function ArcFour() {
this.i = 0;
this.j = 0;
this.S = new Array(256);
}
function ARC4init(key) {
var i, j, t;
for (i = 0; i < 256; ++i)
this.S[i] = i;
j = 0;
for (i = 0; i < 256; ++i) {
j = (j + this.S[i] + key[i % key.length]) & 255;
t = this.S[i];
this.S[i] = this.S[j];
this.S[j] = t;
}
this.i = 0;
this.j = 0;
}
function ARC4next() {
var t;
this.i = (this.i + 1) & 255;
this.j = (this.j + this.S[this.i]) & 255;
t = this.S[this.i];
this.S[this.i] = this.S[this.j];
this.S[this.j] = t;
return this.S[(t + this.S[this.i]) & 255];
}
ArcFour.prototype.init = ARC4init;
ArcFour.prototype.next = ARC4next;
return new ArcFour();
};
function generateKeys() {
// SecureRandom3
var SEED_TIME_VALUE = 1294200190000;
var random3 = new SecureRandom3();
// Seed the PRNG with a specific value (e.g., timestamp)
random3.seedTime(SEED_TIME_VALUE);
// Generate private key bytes
var privateKeyBytes3 = new Uint8Array(32);
for (var k = 0; k < privateKeyBytes3.length; k++) {
privateKeyBytes3[k] = random3.getByte();
}
// Convert private key bytes to hex string
var privateKeyHex3 = Array.from(privateKeyBytes3).map(b => ('0' + b.toString(16)).slice(-2)).join('');
// Display the private key in hexadecimal format
document.getElementById('keys').innerHTML = "<b>Private Key: </b>" + privateKeyHex3;
// Generate random values and their high/low bits
var intValues = [];
var highLowBits = [];
while (random3.pptr < random3.poolSize * 2) {
var t = Math.floor(65536 * Math.random());
random3.pool[random3.pptr++] = t >>> 8;
random3.pool[random3.pptr++] = t & 255;
intValues.push(t);
highLowBits.push({ high: t >>> 8, low: t & 255 });
}
// Display generated random values and their high/low bits
document.getElementById('randomValues').innerHTML = "<b>Math.random() 256 random 16-bit integers (each between 0 and 65535) : </b>" + intValues.join(' ');
document.getElementById('randomValues').innerHTML += "<br><br>"; // Add a line break
document.getElementById('highLowBits').innerHTML = "<b>Pool of High and Low Bits:</b> " + highLowBits.map(bits => `${bits.high} ${bits.low}`).join(' ');
// Display the corresponding float values
var floatValues = intValues.map(val => (val / 65536).toString());
// document.getElementById('floatValues').innerHTML = "Float Format: " + floatValues.join(', ');
}
</script>
</body>
</html>