Skip to content

Commit 5144a7f

Browse files
committed
Clean up
1 parent 65a2921 commit 5144a7f

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

src/app/decrypt/page.jsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* cryptographic libraries
3+
* - web crypto api - https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
4+
* - PyCrypto: https://www.dlitz.net/software/pycrypto/api/2.6/
5+
* - cryptography.io: https://cryptography.io/en/latest/
6+
* - pycryptodome: https://pycryptodome.readthedocs.io/en/latest/
7+
*/
8+
19
"use client";
210

311
import { useState } from "react";
@@ -31,7 +39,7 @@ export default function DecryptPage() {
3139
formData.append("method", method);
3240
formData.append("key", key);
3341

34-
// Add AES-specific parameters
42+
// add AES-specific params
3543
if (method === "aes") {
3644
formData.append("key_size", parseInt(aesKeySize));
3745
formData.append("block_mode", aesMode);
@@ -50,7 +58,6 @@ export default function DecryptPage() {
5058
const blob = await response.blob();
5159
const url = window.URL.createObjectURL(blob);
5260

53-
// Get filename from Content-Disposition header or derive from original
5461
const contentDisposition = response.headers.get('Content-Disposition');
5562
let filename = file.name.replace('encrypted_', '');
5663
if (contentDisposition && contentDisposition.includes('filename=')) {

src/app/encrypt/page.jsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* cryptographic libraries
3+
* - web crypto api - https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
4+
* - PyCrypto: https://www.dlitz.net/software/pycrypto/api/2.6/
5+
* - cryptography.io: https://cryptography.io/en/latest/
6+
* - pycryptodome: https://pycryptodome.readthedocs.io/en/latest/
7+
*/
8+
19
"use client";
210

311
import { useState } from "react";
@@ -19,15 +27,15 @@ export default function EncryptPage() {
1927
const [loading, setLoading] = useState(false);
2028
const [message, setMessage] = useState({ text: "", type: "" });
2129

22-
const RSA_MAX_SIZE = 190; // Maximum size in bytes for RSA-2048 with OAEP padding
30+
const RSA_MAX_SIZE = 190; // the max size in bytes for RSA-2048 with OAEP padding
2331

2432
const handleEncrypt = async () => {
2533
if (!file || (!key && method !== "rsa")) {
2634
setMessage({ text: "Please select a file and enter a key (except RSA).", type: "error" });
2735
return;
2836
}
2937

30-
// Check file size for RSA
38+
// check file size for RSA
3139
if (method === "rsa" && file.size > RSA_MAX_SIZE) {
3240
setMessage({
3341
text: `RSA encryption is limited to files smaller than ${RSA_MAX_SIZE} bytes. Your file is ${file.size} bytes. Please use AES or 3DES for larger files.`,
@@ -36,7 +44,7 @@ export default function EncryptPage() {
3644
return;
3745
}
3846

39-
// Check key length for 3DES
47+
// check key length for 3DES
4048
if (method === "3des" && key.length < 16) {
4149
setMessage({
4250
text: `3DES key must be at least 16 characters long. Your key is ${key.length} characters.`,
@@ -51,7 +59,7 @@ export default function EncryptPage() {
5159
formData.append("method", method);
5260
formData.append("key", key);
5361

54-
// Add AES-specific parameters
62+
// add AES params
5563
if (method === "aes") {
5664
formData.append("key_size", parseInt(aesKeySize));
5765
formData.append("block_mode", aesMode);
@@ -70,7 +78,6 @@ export default function EncryptPage() {
7078
const blob = await response.blob();
7179
const url = window.URL.createObjectURL(blob);
7280

73-
// Get filename from Content-Disposition header or create one from original
7481
const contentDisposition = response.headers.get('Content-Disposition');
7582
let filename = `encrypted_${file.name}`;
7683
if (contentDisposition && contentDisposition.includes('filename=')) {

src/app/hash/page.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* cryptographic libraries
3+
* - hashlib (Python standard library) - https://docs.python.org/3/library/hashlib.html
4+
*/
5+
16
"use client";
27

38
import { useState } from "react";
@@ -173,7 +178,7 @@ export default function HashPage() {
173178
{loading ? "Comparing..." : "Compare File Hashes"}
174179
</button>
175180

176-
{/* Display single hash result */}
181+
{/* display single hash result */}
177182
{hashResult && compareResult === null && (
178183
<div className="p-4 rounded-md bg-gray-900/50">
179184
<div className="flex items-center text-sm text-gray-300 break-all font-mono">

src/app/keygen/page.jsx

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* cryptographic libraries
3+
* - web crypto api - https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
4+
* - generateKey: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
5+
* - deriveKey: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveKey
6+
* - exportKey: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/exportKey
7+
* - ECDH (P-256): https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveKey#ecdh
8+
* - RSA-OAEP: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey#rsa-oaep
9+
*/
10+
111
"use client";
212

313
import { useState } from "react";
@@ -155,10 +165,10 @@ export default function KeygenPage() {
155165

156166
let otherPublicKey;
157167
if (dhState.otherKeyPair) {
158-
// If we generated the other party's key, use it directly
168+
// if we generated the other party's key, use it directly
159169
otherPublicKey = dhState.otherKeyPair.publicKey;
160170
} else {
161-
// Convert base64 public key back to CryptoKey
171+
// convert base64 public key back to CryptoKey
162172
const binaryStr = atob(dhState.otherPublicKey);
163173
const bytes = new Uint8Array(binaryStr.length);
164174
for (let i = 0; i < binaryStr.length; i++) {
@@ -175,7 +185,7 @@ export default function KeygenPage() {
175185
);
176186
}
177187

178-
// Derive shared secret
188+
// deirve shared secret
179189
const sharedKey = await crypto.subtle.deriveKey(
180190
{ name: "ECDH", public: otherPublicKey },
181191
dhState.myKeyPair.privateKey,
@@ -216,18 +226,18 @@ export default function KeygenPage() {
216226
if (includeSymbols) charset += symbols;
217227

218228
let password = '';
219-
// Ensure at least one character from each selected type
229+
// at least one character from each selected type
220230
if (includeUppercase) password += uppercase[Math.floor(Math.random() * uppercase.length)];
221231
password += lowercase[Math.floor(Math.random() * lowercase.length)];
222232
if (includeNumbers) password += numbers[Math.floor(Math.random() * numbers.length)];
223233
if (includeSymbols) password += symbols[Math.floor(Math.random() * symbols.length)];
224234

225-
// Fill the rest randomly
235+
// fill the rest randomly
226236
while (password.length < length) {
227237
password += charset[Math.floor(Math.random() * charset.length)];
228238
}
229239

230-
// Shuffle the password
240+
// shuffle the password
231241
password = password.split('').sort(() => Math.random() - 0.5).join('');
232242

233243
setPassword(password);
@@ -287,7 +297,7 @@ export default function KeygenPage() {
287297
)}
288298

289299
<div className="space-y-6">
290-
{/* AES Key Generation */}
300+
{/* AES key gen */}
291301
<div className="space-y-4 p-4 rounded-md bg-gray-900/50">
292302
<h3 className="text-xl font-semibold text-white flex items-center">
293303
<FaLock className="w-5 h-5 mr-2" />
@@ -323,7 +333,7 @@ export default function KeygenPage() {
323333
)}
324334
</div>
325335

326-
{/* RSA Key Generation */}
336+
{/* RSA key gen */}
327337
<div className="space-y-4 p-4 rounded-md bg-gray-900/50">
328338
<h3 className="text-xl font-semibold text-white flex items-center">
329339
<FaKey className="w-5 h-5 mr-2" />
@@ -374,7 +384,7 @@ export default function KeygenPage() {
374384
)}
375385
</div>
376386

377-
{/* DH Key Exchange */}
387+
{/* DH key exchange */}
378388
<div className="space-y-4 p-4 rounded-md bg-gray-900/50">
379389
<h3 className="text-xl font-semibold text-white flex items-center">
380390
<FaExchangeAlt className="w-5 h-5 mr-2" />
@@ -463,7 +473,7 @@ export default function KeygenPage() {
463473
</div>
464474
</div>
465475

466-
{/* Password Generation */}
476+
{/* password gen */}
467477
<div className="space-y-4 p-4 rounded-md bg-gray-900/50">
468478
<h3 className="text-xl font-semibold text-white flex items-center">
469479
<FaAsterisk className="w-5 h-5 mr-2" />

src/app/steganography/page.jsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import {
1414
FaSearch
1515
} from "react-icons/fa";
1616

17-
// API base URL from environment variable
1817
const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5000';
1918
console.log('API URL:', API_URL); // Debug log
2019

2120
export default function SteganographyPage() {
22-
// State management for file handling and UI
21+
2322
const [coverFile, setCoverFile] = useState(null);
2423
const [secretFile, setSecretFile] = useState(null);
2524
const [mode, setMode] = useState("fixed");
@@ -114,7 +113,7 @@ export default function SteganographyPage() {
114113
</div>
115114

116115
<div className="space-y-6">
117-
{/* Operation Select */}
116+
{/* operation select */}
118117
<div>
119118
<label className="block text-sm font-medium text-gray-300">
120119
<div className="flex items-center">
@@ -132,7 +131,7 @@ export default function SteganographyPage() {
132131
</select>
133132
</div>
134133

135-
{/* Cover File Upload */}
134+
{/* cover file upload */}
136135
<div>
137136
<label className="block text-sm font-medium text-gray-300">
138137
<div className="flex items-center">
@@ -147,7 +146,7 @@ export default function SteganographyPage() {
147146
/>
148147
</div>
149148

150-
{/* Secret File Upload (only for embed) */}
149+
{/* secret file upload (only for embed) */}
151150
{operation === "embed" && (
152151
<div>
153152
<label className="block text-sm font-medium text-gray-300">
@@ -164,7 +163,7 @@ export default function SteganographyPage() {
164163
</div>
165164
)}
166165

167-
{/* Mode Select */}
166+
{/* mode select */}
168167
<div>
169168
<label className="block text-sm font-medium text-gray-300">
170169
<div className="flex items-center">
@@ -182,7 +181,7 @@ export default function SteganographyPage() {
182181
</select>
183182
</div>
184183

185-
{/* S and L Parameters */}
184+
{/* S and L params */}
186185
<div className="grid grid-cols-2 gap-4">
187186
<div>
188187
<label className="block text-sm font-medium text-gray-300">
@@ -210,7 +209,7 @@ export default function SteganographyPage() {
210209
</div>
211210
</div>
212211

213-
{/* Check Capacity Button */}
212+
{/* check cap cutton */}
214213
<button
215214
onClick={checkCapacity}
216215
disabled={loading || !coverFile}
@@ -220,14 +219,14 @@ export default function SteganographyPage() {
220219
{loading ? "Checking..." : "Check Capacity"}
221220
</button>
222221

223-
{/* Capacity Display */}
222+
{/* cap display */}
224223
{capacity !== null && (
225224
<div className="p-4 rounded-md bg-gray-900/50 text-gray-300">
226225
Available Capacity: {capacity} bits ({Math.floor(capacity / 8)} bytes)
227226
</div>
228227
)}
229228

230-
{/* Operation Button */}
229+
{/* operation button */}
231230
<button
232231
onClick={handleOperation}
233232
disabled={loading || !coverFile || (operation === "embed" && !secretFile)}
@@ -237,7 +236,7 @@ export default function SteganographyPage() {
237236
{loading ? "Processing..." : (operation === "embed" ? "Embed File" : "Extract File")}
238237
</button>
239238

240-
{/* Download Output File */}
239+
{/* download output file */}
241240
{outputFileUrl && (
242241
<a
243242
href={outputFileUrl}

0 commit comments

Comments
 (0)