-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeadEdgeCryptography.html
More file actions
339 lines (302 loc) · 13 KB
/
LeadEdgeCryptography.html
File metadata and controls
339 lines (302 loc) · 13 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lead Edge Cryptography Prototype</title>
<style>
body {
background-color: black;
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
flex-direction: column;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
max-width: 875px;
padding: 20px;
background-color: rgba(34, 34, 34, 0.8); /* Semi-transparent smoky gray */
border-radius: 10px;
overflow: hidden;
}
.form-group {
margin-bottom: 15px;
width: 100%;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"], textarea {
width: 100%;
padding: 8px;
box-sizing: border-box;
border-radius: 5px;
border: none;
}
button {
padding: 10px 20px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.output {
width: 875px;
margin-top: 20px;
padding: 10px;
border: 1px solid #ddd;
background-color: #333;
border-radius: 5px;
word-wrap: break-word;
max-height: 200px; /* Set a maximum height */
overflow-y: auto; /* Make the container scrollable */
}
#mazeCanvas {
display: block;
margin: 50px auto;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<div class="container">
<h1>Lead Edge Cryptography Prototype</h1>
<button onclick="generateMaze()">Generate Lead Edge Maze</button>
<canvas id="mazeCanvas" width="875" height="875"></canvas>
<div class="form-group">
<label for="message">Message to Encrypt</label>
<textarea id="message" rows="4"></textarea>
</div>
<div class="form-group">
<button onclick="encryptMessage()">Encrypt Message</button>
</div>
<div class="output" id="encryption-output"></div>
<div class="form-group">
<label for="publicKey">Public Key</label>
<input type="text" id="publicKey">
</div>
<div class="form-group">
<button onclick="decryptMessage()">Decrypt Message</button>
</div>
<div class="output" id="decryption-output"></div>
</div>
<script>
const canvas = document.getElementById('mazeCanvas');
const ctx = canvas.getContext('2d');
let mazeSegments = [];
const unitSize = 30; // Default unit size
function generateMaze() {
ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas
resetForms(); // Reset the forms below
const mazeWidth = Math.floor(canvas.width / unitSize);
const mazeHeight = Math.floor(canvas.height / unitSize);
const grid = createGrid(mazeWidth, mazeHeight);
const { entry, exit } = createPath(grid, mazeWidth, mazeHeight);
mazeSegments = extractMazeSegments(grid, mazeWidth, mazeHeight);
drawGrid(grid, mazeWidth, mazeHeight, entry, exit);
}
function createGrid(width, height) {
const grid = [];
for (let y = 0; y < height; y++) {
const row = [];
for (let x = 0; x < width; x++) {
row.push({
top: true,
right: true,
bottom: true,
left: true
});
}
grid.push(row);
}
return grid;
}
function createPath(grid, width, height) {
const stack = [];
const entry = { x: 0, y: Math.floor(Math.random() * height) };
const exit = { x: width - 1, y: Math.floor(Math.random() * height) };
let current = entry;
const visited = new Set([`${current.x},${current.y}`]);
while (stack.length > 0 || (current && (current.x !== exit.x || current.y !== exit.y))) {
const neighbors = getUnvisitedNeighbors(current, visited, width, height);
if (neighbors.length > 0) {
const next = neighbors[Math.floor(Math.random() * neighbors.length)];
if (next) {
removeWall(grid, current, next);
stack.push(current);
visited.add(`${next.x},${next.y}`);
current = next;
} else {
console.error('No valid neighbors found.');
}
} else {
current = stack.pop();
if (!current) break;
}
}
return { entry, exit };
}
function getUnvisitedNeighbors(cell, visited, width, height) {
const neighbors = [];
const { x, y } = cell;
if (x > 0 && !visited.has(`${x - 1},${y}`)) neighbors.push({ x: x - 1, y });
if (x < width - 1 && !visited.has(`${x + 1},${y}`)) neighbors.push({ x: x + 1, y });
if (y > 0 && !visited.has(`${x},${y - 1}`)) neighbors.push({ x, y: y - 1 });
if (y < height - 1 && !visited.has(`${x},${y + 1}`)) neighbors.push({ x, y: y + 1 });
return neighbors;
}
function removeWall(grid, current, next) {
if (current.x === next.x) {
if (current.y > next.y) {
grid[current.y][current.x].top = false;
grid[next.y][next.x].bottom = false;
} else {
grid[current.y][current.x].bottom = false;
grid[next.y][next.x].top = false;
}
} else {
if (current.x > next.x) {
grid[current.y][current.x].left = false;
grid[next.y][next.x].right = false;
} else {
grid[current.y][current.x].right = false;
grid[next.y][next.x].left = false;
}
}
}
function drawGrid(grid, width, height, entry, exit) {
const cellSize = canvas.width / Math.max(width, height);
ctx.strokeStyle = '#FFF';
ctx.lineWidth = 2;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const cell = grid[y][x];
const xPos = x * cellSize;
const yPos = y * cellSize;
if (cell.top) {
ctx.beginPath();
ctx.moveTo(xPos, yPos);
ctx.lineTo(xPos + cellSize, yPos);
ctx.stroke();
}
if (cell.right) {
ctx.beginPath();
ctx.moveTo(xPos + cellSize, yPos);
ctx.lineTo(xPos + cellSize, yPos + cellSize);
ctx.stroke();
}
if (cell.bottom) {
ctx.beginPath();
ctx.moveTo(xPos, yPos + cellSize);
ctx.lineTo(xPos + cellSize, yPos + cellSize);
ctx.stroke();
}
if (cell.left) {
ctx.beginPath();
ctx.moveTo(xPos, yPos);
ctx.lineTo(xPos, yPos + cellSize);
ctx.stroke();
}
}
}
// Draw entry and exit points
ctx.clearRect(entry.x * cellSize, entry.y * cellSize, cellSize, cellSize);
ctx.clearRect(exit.x * cellSize, exit.y * cellSize, cellSize, cellSize);
// Draw the blue border
ctx.strokeStyle = 'blue';
ctx.lineWidth = 4;
ctx.strokeRect(0, 0, canvas.width, canvas.height);
// Create single-unit openings in the blue perimeter for entry and exit
ctx.clearRect(entry.x * cellSize, entry.y * cellSize, cellSize, cellSize);
ctx.clearRect(exit.x * cellSize, exit.y * cellSize, cellSize, cellSize);
}
function extractMazeSegments(grid, width, height) {
const cellSize = canvas.width / Math.max(width, height);
const segments = [];
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const cell = grid[y][x];
if (cell.top) segments.push({ x1: x * cellSize, y1: y * cellSize, x2: (x + 1) * cellSize, y2: y * cellSize });
if (cell.right) segments.push({ x1: (x + 1) * cellSize, y1: y * cellSize, x2: (x + 1) * cellSize, y2: (y + 1) * cellSize });
if (cell.bottom) segments.push({ x1: x * cellSize, y1: (y + 1) * cellSize, x2: (x + 1) * cellSize, y2: (y + 1) * cellSize });
if (cell.left) segments.push({ x1: x * cellSize, y1: y * cellSize, x2: x * cellSize, y2: (y + 1) * cellSize });
}
}
return segments;
}
function resetForms() {
document.getElementById('message').value = '';
document.getElementById('publicKey').value = '';
document.getElementById('encryption-output').innerHTML = '';
document.getElementById('decryption-output').innerHTML = '';
}
function generateKey() {
return Math.random().toString(36).substring(2);
}
function customEncrypt(message, segments) {
// Custom encryption logic using Lead Edge Cryptography
const Mid = segments.length;
const id = segments.map(s => `${s.x1},${s.y1},${s.x2},${s.y2}`).join(';');
const Cih = message.split('').map((char, i) => char.charCodeAt(0) * (i + 1)).reduce((acc, val) => acc + val, 0);
const Hd = ((Cih * Mid) / (Mid + 1)) ** 2;
let encrypted = "";
for (let i = 0; i < message.length; i++) {
const charCode = message.charCodeAt(i);
const segment = segments[i % segments.length];
const newCharCode = (charCode + Hd + segment.x1 + segment.y1) % 256; // Simplified encryption logic
encrypted += String.fromCharCode(newCharCode);
}
return btoa(encrypted);
}
function customDecrypt(encryptedMessage, segments) {
const decodedMessage = atob(encryptedMessage);
const Mid = segments.length;
const Cih = decodedMessage.split('').map((char, i) => char.charCodeAt(0) * (i + 1)).reduce((acc, val) => acc + val, 0);
const Hd = ((Cih * Mid) / (Mid + 1)) ** 2;
let decrypted = "";
for (let i = 0; i < decodedMessage.length; i++) {
const charCode = decodedMessage.charCodeAt(i);
const segment = segments[i % segments.length];
const originalCharCode = (charCode - Hd - segment.x1 - segment.y1 + 256) % 256; // Simplified decryption logic
decrypted += String.fromCharCode(originalCharCode);
}
return decrypted;
}
function encryptMessage() {
const message = document.getElementById('message').value;
const publicKey = generateKey();
const privateKey = generateKey();
// Encrypt the message using custom logic and segment points
const encryptedMessage = customEncrypt(message, mazeSegments);
document.getElementById('encryption-output').innerHTML = `
<p><strong>Encrypted Message:</strong> ${encryptedMessage}</p>
<p><strong>Public Key:</strong> ${publicKey}</p>
<p><strong>Private Key:</strong> ${privateKey}</p>
`;
document.getElementById('publicKey').value = publicKey;
}
function decryptMessage() {
const encryptedMessage = document.querySelector('#encryption-output p:nth-child(1) strong').innerText;
const publicKey = document.getElementById('publicKey').value;
// Decrypt the message using custom logic and segment points
const decryptedMessage = customDecrypt(encryptedMessage, mazeSegments);
document.getElementById('decryption-output').innerHTML = `
<p><strong>Decrypted Message:</strong> ${decryptedMessage}</p>
`;
}
// Initial maze generation
generateMaze();
</script>
</body>
</html>