-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
403 lines (348 loc) · 17.7 KB
/
index.html
File metadata and controls
403 lines (348 loc) · 17.7 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Classical Cryptography Suite</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="icon" href="favicon.png" type="image/x-icon">
</head>
<body data-color-scheme="dark">
<div class="app">
<!-- Header -->
<header class="header">
<div class="container">
<div class="header-content">
<h1>Classical Cryptography Suite</h1>
<p class="header-subtitle">Advanced encryption and decryption tools with educational content for beginners and experts</p>
</div>
</div>
</header>
<!-- Main Content -->
<main class="main">
<div class="container">
<!-- Algorithm Selection Tabs -->
<div class="tabs">
<button class="tab-btn active" data-tab="caesar">Caesar Cipher</button>
<button class="tab-btn" data-tab="vigenere">Vigenère Cipher</button>
<button class="tab-btn" data-tab="analysis">Security Analysis</button>
<button class="tab-btn" data-tab="code">View Code</button>
</div>
<!-- Caesar Cipher Tab -->
<div id="caesar-tab" class="tab-content active">
<div class="cipher-section">
<div class="controls-section">
<h2>Caesar Cipher</h2>
<p class="algorithm-description">A substitution cipher where each letter is shifted by a fixed number of positions in the alphabet.</p>
<div class="form-group">
<label for="caesar-shift" class="form-label">Shift Value (1-25):</label>
<input type="range" id="caesar-shift" class="form-control" min="1" max="25" value="3">
<span id="caesar-shift-value" class="shift-display">3</span>
</div>
<div class="mode-selector">
<label class="form-label">Mode:</label>
<div class="radio-group">
<label><input type="radio" name="caesar-mode" value="encrypt" checked> Encrypt</label>
<label><input type="radio" name="caesar-mode" value="decrypt"> Decrypt</label>
</div>
</div>
</div>
<div class="text-processing">
<div class="text-group">
<label for="caesar-input" class="form-label">Input Text:</label>
<textarea id="caesar-input" class="form-control" placeholder="Enter your text here..." rows="4"></textarea>
</div>
<div class="text-group">
<label for="caesar-output" class="form-label">Output Text:</label>
<textarea id="caesar-output" class="form-control" readonly rows="4"></textarea>
<button id="copy-caesar" class="btn btn--secondary btn--sm">Copy Result</button>
</div>
</div>
<div class="explanation-section">
<h3>How it works:</h3>
<div id="caesar-explanation" class="explanation-content">
<p><strong>Formula:</strong> E(x) = (x + n) mod 26 for encryption</p>
<p><strong>Example:</strong> With shift=3, 'A' becomes 'D', 'B' becomes 'E', etc.</p>
</div>
</div>
<div class="attack-section">
<h3>Security Demonstration:</h3>
<button id="brute-force-caesar" class="btn btn--primary">Simulate Brute Force Attack</button>
<div id="brute-force-results" class="attack-results hidden"></div>
</div>
</div>
</div>
<!-- Vigenère Cipher Tab -->
<div id="vigenere-tab" class="tab-content">
<div class="cipher-section">
<div class="controls-section">
<h2>Vigenère Cipher</h2>
<p class="algorithm-description">A polyalphabetic substitution cipher using a keyword to vary the Caesar shift.</p>
<div class="form-group">
<label for="vigenere-key" class="form-label">Encryption Key:</label>
<input type="text" id="vigenere-key" class="form-control" placeholder="Enter key (letters only)" value="KEY">
</div>
<div class="mode-selector">
<label class="form-label">Mode:</label>
<div class="radio-group">
<label><input type="radio" name="vigenere-mode" value="encrypt" checked> Encrypt</label>
<label><input type="radio" name="vigenere-mode" value="decrypt"> Decrypt</label>
</div>
</div>
</div>
<div class="text-processing">
<div class="text-group">
<label for="vigenere-input" class="form-label">Input Text:</label>
<textarea id="vigenere-input" class="form-control" placeholder="Enter your text here..." rows="4"></textarea>
</div>
<div class="text-group">
<label for="vigenere-output" class="form-label">Output Text:</label>
<textarea id="vigenere-output" class="form-control" readonly rows="4"></textarea>
<button id="copy-vigenere" class="btn btn--secondary btn--sm">Copy Result</button>
</div>
</div>
<div class="explanation-section">
<h3>How it works:</h3>
<div id="vigenere-explanation" class="explanation-content">
<p><strong>Formula:</strong> E(i) = (P(i) + K(i mod m)) mod 26</p>
<p><strong>Key repeating:</strong> The key repeats to match the text length</p>
<div id="vigenere-demo"></div>
</div>
</div>
<div class="attack-section">
<h3>Security Demonstration:</h3>
<button id="kasiski-analysis" class="btn btn--primary">Kasiski Examination Demo</button>
<div id="kasiski-results" class="attack-results hidden"></div>
</div>
</div>
</div>
<!-- Security Analysis Tab -->
<div id="analysis-tab" class="tab-content">
<div class="analysis-section">
<h2>Security Analysis & Cryptanalysis</h2>
<div class="analysis-grid">
<div class="analysis-card">
<h3>Frequency Analysis</h3>
<p>Analyze letter frequencies in your text to identify patterns</p>
<button id="frequency-analysis" class="btn btn--primary">Analyze Current Text</button>
<div class="chart-container" style="height: 300px; position: relative;">
<canvas id="frequency-chart"></canvas>
</div>
</div>
<div class="analysis-card">
<h3>Vulnerability Comparison</h3>
<div class="vulnerability-table">
<table>
<thead>
<tr>
<th>Algorithm</th>
<th>Key Space</th>
<th>Security Level</th>
<th>Main Vulnerabilities</th>
</tr>
</thead>
<tbody>
<tr>
<td>Caesar</td>
<td>25</td>
<td><span class="status status--error">Very Low</span></td>
<td>Brute Force, Frequency Analysis</td>
</tr>
<tr>
<td>Vigenère</td>
<td>26^m</td>
<td><span class="status status--warning">Low-Medium</span></td>
<td>Kasiski, Index of Coincidence</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="analysis-card">
<h3>Attack Methods</h3>
<div class="attack-methods">
<div class="attack-method">
<h4>Brute Force Attack</h4>
<p>Effectiveness: 100% against Caesar (25 keys), exponential time for Vigenère</p>
</div>
<div class="attack-method">
<h4>Frequency Analysis</h4>
<p>Most common letters: E(12.7%), T(9.1%), A(8.2%), O(7.5%)</p>
</div>
<div class="attack-method">
<h4>Kasiski Examination</h4>
<p>Finds repeated sequences to determine Vigenère key length</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Code View Tab -->
<div id="code-tab" class="tab-content">
<div class="code-section">
<h2>Implementation Code</h2>
<p class="code-description">Well-commented implementations for educational purposes</p>
<div class="code-selector">
<button class="code-btn active" data-code="caesar">Caesar Implementation</button>
<button class="code-btn" data-code="vigenere">Vigenère Implementation</button>
<button class="code-btn" data-code="attacks">Attack Methods</button>
</div>
<div id="caesar-code" class="code-display active">
<pre><code>/**
* Caesar Cipher Implementation
* Simple substitution cipher with fixed shift
* Time Complexity: O(n) where n is text length
*/
function caesarCipher(text, shift, decrypt = false) {
// Adjust shift for decryption
if (decrypt) shift = 26 - shift;
return text.split('').map(char => {
// Only process alphabetic characters
if (/[A-Za-z]/.test(char)) {
// Get character code and normalize to 0-25
const code = char.toUpperCase().charCodeAt(0) - 65;
// Apply Caesar shift with modulo wrap-around
const shifted = (code + shift) % 26;
// Convert back to character, preserving original case
const newChar = String.fromCharCode(shifted + 65);
return char === char.toLowerCase() ? newChar.toLowerCase() : newChar;
}
// Return non-alphabetic characters unchanged
return char;
}).join('');
}
// Brute force attack simulation
function bruteForceCaesar(ciphertext) {
const results = [];
// Try all possible shifts (1-25)
for (let shift = 1; shift <= 25; shift++) {
const decrypted = caesarCipher(ciphertext, shift, true);
results.push({ shift, text: decrypted });
}
return results;
}</code></pre>
</div>
<div id="vigenere-code" class="code-display">
<pre><code>/**
* Vigenère Cipher Implementation
* Polyalphabetic substitution using keyword
* Time Complexity: O(n) where n is text length
*/
function vigenereCipher(text, key, decrypt = false) {
// Normalize key to uppercase
key = key.toUpperCase().replace(/[^A-Z]/g, '');
if (key.length === 0) return text;
let keyIndex = 0;
return text.split('').map(char => {
// Only process alphabetic characters
if (/[A-Za-z]/.test(char)) {
const textCode = char.toUpperCase().charCodeAt(0) - 65;
const keyCode = key[keyIndex % key.length].charCodeAt(0) - 65;
// Apply Vigenère formula
let shifted;
if (decrypt) {
shifted = (textCode - keyCode + 26) % 26;
} else {
shifted = (textCode + keyCode) % 26;
}
// Increment key position for alphabetic chars only
keyIndex++;
// Convert back to character, preserving case
const newChar = String.fromCharCode(shifted + 65);
return char === char.toLowerCase() ? newChar.toLowerCase() : newChar;
}
return char;
}).join('');
}
// Key length analysis using Index of Coincidence
function indexOfCoincidence(text) {
const counts = {};
let total = 0;
// Count letter frequencies
for (const char of text.toUpperCase()) {
if (/[A-Z]/.test(char)) {
counts[char] = (counts[char] || 0) + 1;
total++;
}
}
// Calculate IC = Σ(ni * (ni-1)) / (N * (N-1))
let sum = 0;
for (const count of Object.values(counts)) {
sum += count * (count - 1);
}
return total > 1 ? sum / (total * (total - 1)) : 0;
}</code></pre>
</div>
<div id="attacks-code" class="code-display">
<pre><code>/**
* Cryptanalysis Attack Methods
* Educational implementations of common attacks
*/
// Frequency analysis for single substitution ciphers
function frequencyAnalysis(text) {
const frequencies = {};
let totalLetters = 0;
// Count each letter
for (const char of text.toUpperCase()) {
if (/[A-Z]/.test(char)) {
frequencies[char] = (frequencies[char] || 0) + 1;
totalLetters++;
}
}
// Convert to percentages
const analysis = [];
for (const [letter, count] of Object.entries(frequencies)) {
analysis.push({
letter,
count,
frequency: ((count / totalLetters) * 100).toFixed(2)
});
}
// Sort by frequency (descending)
return analysis.sort((a, b) => b.count - a.count);
}
// Kasiski Examination for Vigenère cipher
function kasiskiExamination(ciphertext) {
const text = ciphertext.toUpperCase().replace(/[^A-Z]/g, '');
const trigrams = {};
const distances = [];
// Find all trigrams and their positions
for (let i = 0; i <= text.length - 3; i++) {
const trigram = text.substr(i, 3);
if (!trigrams[trigram]) {
trigrams[trigram] = [];
}
trigrams[trigram].push(i);
}
// Calculate distances between repeated trigrams
for (const [trigram, positions] of Object.entries(trigrams)) {
if (positions.length > 1) {
for (let i = 1; i < positions.length; i++) {
distances.push(positions[i] - positions[i-1]);
}
}
}
// Find GCD of distances to estimate key length
return distances.length > 0 ? gcd(...distances) : null;
}
// Greatest Common Divisor helper function
function gcd(a, b) {
return b === 0 ? a : gcd(b, a % b);
}</code></pre>
</div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="footer">
<div class="container">
<p>Educational Cryptography Suite - For learning purposes only. Not suitable for real-world encryption.</p>
</div>
</footer>
</div>
<script src="app.js"></script>
</body>
</html>