ig it seems to be workan rn
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,2 +1,4 @@
|
|||||||
# One Time Pad Cipher Fuckery
|
# One Time Pad Cipher Fuckery
|
||||||
for when __nearly__ impossible to crack just isnt good enoug
|
for when __nearly__ impossible to crack just isnt good enough
|
||||||
|
|
||||||
|
**jfc im high as fuck lmao**
|
||||||
+190
-50
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Random Binary Generator with Monobit Test</title>
|
<title>One-Time Pad Tool</title>
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
--bg-color: #030712;
|
--bg-color: #030712;
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: system-ui, -apple-system, sans-serif;
|
font-family: system-ui, -apple-system, sans-serif;
|
||||||
max-width: 500px;
|
max-width: 520px;
|
||||||
margin: 40px auto;
|
margin: 40px auto;
|
||||||
padding: 0 20px;
|
padding: 0 20px;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
@@ -47,6 +47,9 @@
|
|||||||
font-size: 1.35rem;
|
font-size: 1.35rem;
|
||||||
letter-spacing: -0.01em;
|
letter-spacing: -0.01em;
|
||||||
}
|
}
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
label {
|
label {
|
||||||
display: block;
|
display: block;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@@ -54,24 +57,43 @@
|
|||||||
color: var(--text-main);
|
color: var(--text-main);
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
input[type="number"] {
|
input[type="number"], select {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px 12px;
|
padding: 10px 12px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
margin-bottom: 16px;
|
|
||||||
background-color: var(--input-bg);
|
background-color: var(--input-bg);
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
color: var(--text-main);
|
color: var(--text-main);
|
||||||
font-size: 1rem;
|
font-size: 0.95rem;
|
||||||
}
|
}
|
||||||
input[type="number"]:focus {
|
input[type="file"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background-color: var(--input-bg);
|
||||||
|
border: 1px dashed var(--border-color);
|
||||||
|
border-radius: 6px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
input[type="file"]::file-selector-button {
|
||||||
|
background: var(--border-color);
|
||||||
|
color: var(--text-main);
|
||||||
|
border: none;
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
input:focus, select:focus {
|
||||||
outline: 2px solid var(--primary);
|
outline: 2px solid var(--primary);
|
||||||
border-color: transparent;
|
border-color: transparent;
|
||||||
}
|
}
|
||||||
button {
|
button {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
|
margin-top: 8px;
|
||||||
background-color: var(--primary);
|
background-color: var(--primary);
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
border: none;
|
border: none;
|
||||||
@@ -112,37 +134,76 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h2>CSPRNG Binary Generator</h2>
|
<h2>One-Time Pad Cipher Tool</h2>
|
||||||
<label for="multiplier">Enter Max Message Length (X*16-bits):</label>
|
|
||||||
<input type="number" id="multiplier" min="1" value="600" placeholder="Enter an integer">
|
|
||||||
|
|
||||||
<button id="generateBtn">Generate, Validate & Download</button>
|
<div class="form-group">
|
||||||
|
<label for="modeSelect">Operation Mode:</label>
|
||||||
<div class="info" id="bitCountInfo">
|
<select id="modeSelect">
|
||||||
Total bits: 9,600 bits (1,200 bytes)
|
<option value="encode-new">Encrypt File (Generate New Pad)</option>
|
||||||
|
<option value="encode-existing">Encrypt File (Use Existing Pad)</option>
|
||||||
|
<option value="decode-existing">Decrypt File (Use Existing Pad)</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="messageGroup">
|
||||||
|
<label for="messageInput">Select File / Message:</label>
|
||||||
|
<input type="file" id="messageInput">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="padGroup" style="display: none;">
|
||||||
|
<label for="padInput">Select Existing Key Pad (.pad):</label>
|
||||||
|
<input type="file" id="padInput">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" id="sizeGroup">
|
||||||
|
<label for="multiplier">Pad Block Multiplier (X*16-bits):</label>
|
||||||
|
<input type="number" id="multiplier" min="1" value="600" placeholder="Enter an integer">
|
||||||
|
<div class="info" id="bitCountInfo">
|
||||||
|
Generated pad size: 9,600 bits (1,200 bytes)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id="processBtn">Process & Download</button>
|
||||||
|
|
||||||
<div id="statusBox" class="status"></div>
|
<div id="statusBox" class="status"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
const modeSelect = document.getElementById('modeSelect');
|
||||||
|
const messageInput = document.getElementById('messageInput');
|
||||||
|
const padInput = document.getElementById('padInput');
|
||||||
const multiplierInput = document.getElementById('multiplier');
|
const multiplierInput = document.getElementById('multiplier');
|
||||||
const bitCountInfo = document.getElementById('bitCountInfo');
|
const bitCountInfo = document.getElementById('bitCountInfo');
|
||||||
const generateBtn = document.getElementById('generateBtn');
|
const processBtn = document.getElementById('processBtn');
|
||||||
const statusBox = document.getElementById('statusBox');
|
const statusBox = document.getElementById('statusBox');
|
||||||
|
|
||||||
|
const padGroup = document.getElementById('padGroup');
|
||||||
|
const sizeGroup = document.getElementById('sizeGroup');
|
||||||
|
|
||||||
|
// Toggle visible UI controls depending on selected mode
|
||||||
|
modeSelect.addEventListener('change', () => {
|
||||||
|
const mode = modeSelect.value;
|
||||||
|
if (mode === 'encode-new') {
|
||||||
|
padGroup.style.display = 'none';
|
||||||
|
sizeGroup.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
padGroup.style.display = 'block';
|
||||||
|
sizeGroup.style.display = 'none';
|
||||||
|
}
|
||||||
|
statusBox.style.display = 'none';
|
||||||
|
});
|
||||||
|
|
||||||
multiplierInput.addEventListener('input', () => {
|
multiplierInput.addEventListener('input', () => {
|
||||||
const x = parseInt(multiplierInput.value, 10) || 0;
|
const x = parseInt(multiplierInput.value, 10) || 0;
|
||||||
const bits = x * 16;
|
const bits = x * 16;
|
||||||
const bytes = bits / 8;
|
const bytes = bits / 8;
|
||||||
bitCountInfo.textContent = `Total bits: ${bits.toLocaleString()} bits (${bytes.toLocaleString()} bytes)`;
|
bitCountInfo.textContent = `Generated pad size: ${bits.toLocaleString()} bits (${bytes.toLocaleString()} bytes)`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger generator when pressing Enter inside the input field
|
|
||||||
multiplierInput.addEventListener('keydown', (event) => {
|
multiplierInput.addEventListener('keydown', (event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
generateBtn.click();
|
processBtn.click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -171,7 +232,6 @@
|
|||||||
for (let i = 0; i < uint8Array.length; i++) {
|
for (let i = 0; i < uint8Array.length; i++) {
|
||||||
let byte = uint8Array[i];
|
let byte = uint8Array[i];
|
||||||
for (let bit = 0; bit < 8; bit++) {
|
for (let bit = 0; bit < 8; bit++) {
|
||||||
// Convert bit (0 -> -1, 1 -> +1)
|
|
||||||
sum += ((byte >> bit) & 1) ? 1 : -1;
|
sum += ((byte >> bit) & 1) ? 1 : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,7 +239,6 @@
|
|||||||
const sObs = Math.abs(sum) / Math.sqrt(totalBits);
|
const sObs = Math.abs(sum) / Math.sqrt(totalBits);
|
||||||
const pValue = erfc(sObs / Math.sqrt(2));
|
const pValue = erfc(sObs / Math.sqrt(2));
|
||||||
|
|
||||||
// NIST standard threshold: p-value must be >= 0.01 to pass
|
|
||||||
return {
|
return {
|
||||||
passed: pValue >= 0.01,
|
passed: pValue >= 0.01,
|
||||||
pValue: pValue,
|
pValue: pValue,
|
||||||
@@ -188,7 +247,6 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to generate a cryptographically secure 8-digit random integer string
|
|
||||||
function generateRandom8Digits() {
|
function generateRandom8Digits() {
|
||||||
const randomBuffer = new Uint32Array(1);
|
const randomBuffer = new Uint32Array(1);
|
||||||
window.crypto.getRandomValues(randomBuffer);
|
window.crypto.getRandomValues(randomBuffer);
|
||||||
@@ -196,53 +254,135 @@
|
|||||||
return num.toString();
|
return num.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
generateBtn.addEventListener('click', () => {
|
// Reads a File object into an ArrayBuffer asynchronously
|
||||||
statusBox.style.display = 'none';
|
function readFileAsBuffer(file) {
|
||||||
const x = parseInt(multiplierInput.value, 10);
|
return new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => resolve(new Uint8Array(reader.result));
|
||||||
|
reader.onerror = () => reject(reader.error);
|
||||||
|
reader.readAsArrayBuffer(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (isNaN(x) || x < 1) {
|
// Helper to trigger direct browser file download
|
||||||
alert('Please enter a valid positive integer for X.');
|
function triggerDownload(uint8Array, filename) {
|
||||||
|
const blob = new Blob([uint8Array], { type: 'application/octet-stream' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
processBtn.addEventListener('click', async () => {
|
||||||
|
statusBox.style.display = 'none';
|
||||||
|
const mode = modeSelect.value;
|
||||||
|
|
||||||
|
if (!messageInput.files.length) {
|
||||||
|
alert('Please select a input message/file to process.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const byteCount = x * 2;
|
const messageFile = messageInput.files[0];
|
||||||
const buffer = new Uint8Array(byteCount);
|
let messageData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. Generate CSPRNG bytes
|
messageData = await readFileAsBuffer(messageFile);
|
||||||
window.crypto.getRandomValues(buffer);
|
} catch (err) {
|
||||||
|
alert('Error reading input message file: ' + err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Perform Randomness Check
|
const randomPrefix = generateRandom8Digits();
|
||||||
const testResult = runMonobitTest(buffer);
|
|
||||||
|
|
||||||
if (!testResult.passed) {
|
// MODE 1: Encrypt with a newly generated CSPRNG pad
|
||||||
|
if (mode === 'encode-new') {
|
||||||
|
const x = parseInt(multiplierInput.value, 10);
|
||||||
|
if (isNaN(x) || x < 1) {
|
||||||
|
alert('Please enter a valid positive integer for X.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const generatedPadByteCount = x * 2;
|
||||||
|
if (messageData.length > generatedPadByteCount) {
|
||||||
statusBox.className = 'status error';
|
statusBox.className = 'status error';
|
||||||
statusBox.innerHTML = `<strong>Test Failed!</strong><br>Sequence failed Monobit randomness test (P-value: ${testResult.pValue.toFixed(4)} < 0.01). Download aborted.`;
|
statusBox.innerHTML = `<strong>Encryption Failed!</strong><br>Message size (${messageData.length.toLocaleString()} bytes) exceeds pad size (${generatedPadByteCount.toLocaleString()} bytes). Increase X.`;
|
||||||
statusBox.style.display = 'block';
|
statusBox.style.display = 'block';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display Success Stats
|
const padData = new Uint8Array(generatedPadByteCount);
|
||||||
|
window.crypto.getRandomValues(padData);
|
||||||
|
|
||||||
|
const testResult = runMonobitTest(padData);
|
||||||
|
if (!testResult.passed) {
|
||||||
|
statusBox.className = 'status error';
|
||||||
|
statusBox.innerHTML = `<strong>Randomness Check Failed!</strong><br>Generated key failed Monobit test (P-value: ${testResult.pValue.toFixed(4)} < 0.01). Process aborted.`;
|
||||||
|
statusBox.style.display = 'block';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bitwise XOR encryption
|
||||||
|
const cipherData = new Uint8Array(messageData.length);
|
||||||
|
for (let i = 0; i < messageData.length; i++) {
|
||||||
|
cipherData[i] = messageData[i] ^ padData[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger downloads for both the cipher text and key pad
|
||||||
|
triggerDownload(cipherData, `${randomPrefix}_${messageFile.name}.enc`);
|
||||||
|
triggerDownload(padData, `${randomPrefix}_onetime_${x}x16bits.pad`);
|
||||||
|
|
||||||
statusBox.className = 'status success';
|
statusBox.className = 'status success';
|
||||||
statusBox.innerHTML = `<strong>Randomness Test Passed!</strong><br>` +
|
statusBox.innerHTML = `<strong>Encryption Complete!</strong><br>` +
|
||||||
`P-value: ${testResult.pValue.toFixed(4)} (≥ 0.01)<br>` +
|
`Monobit P-value: ${testResult.pValue.toFixed(4)}<br>` +
|
||||||
`Bit distribution: ${testResult.onesCount} ones out of ${testResult.totalBits} bits.`;
|
`Downloaded: Encrypted payload and matching <code>.pad</code> key.`;
|
||||||
statusBox.style.display = 'block';
|
statusBox.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Trigger Download with random 8-digit prefix
|
// MODE 2 & 3: Encrypt or Decrypt using a supplied .pad file
|
||||||
const randomPrefix = generateRandom8Digits();
|
else {
|
||||||
const blob = new Blob([buffer], { type: 'application/octet-stream' });
|
if (!padInput.files.length) {
|
||||||
const url = URL.createObjectURL(blob);
|
alert('Please select an existing .pad file.');
|
||||||
const a = document.createElement('a');
|
return;
|
||||||
a.href = url;
|
}
|
||||||
a.download = `${randomPrefix}_onetime_${x}x16bits.pad`;
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
|
|
||||||
document.body.removeChild(a);
|
let padData;
|
||||||
URL.revokeObjectURL(url);
|
try {
|
||||||
} catch (error) {
|
padData = await readFileAsBuffer(padInput.files[0]);
|
||||||
alert('An error occurred during process: ' + error.message);
|
} catch (err) {
|
||||||
|
alert('Error reading key pad file: ' + err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (messageData.length > padData.length) {
|
||||||
|
statusBox.className = 'status error';
|
||||||
|
statusBox.innerHTML = `<strong>Process Failed!</strong><br>Payload length (${messageData.length.toLocaleString()} bytes) exceeds key pad length (${padData.length.toLocaleString()} bytes).`;
|
||||||
|
statusBox.style.display = 'block';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bitwise XOR operation (Symmetric)
|
||||||
|
const outputData = new Uint8Array(messageData.length);
|
||||||
|
for (let i = 0; i < messageData.length; i++) {
|
||||||
|
outputData[i] = messageData[i] ^ padData[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === 'encode-existing') {
|
||||||
|
triggerDownload(outputData, `${randomPrefix}_${messageFile.name}.enc`);
|
||||||
|
statusBox.className = 'status success';
|
||||||
|
statusBox.innerHTML = `<strong>Encryption Complete!</strong><br>File encrypted using supplied key pad.`;
|
||||||
|
} else {
|
||||||
|
// Strip .enc extension if present during decryption
|
||||||
|
let originalName = messageFile.name.replace(/\.enc$/i, '');
|
||||||
|
triggerDownload(outputData, `decrypted_${originalName}`);
|
||||||
|
statusBox.className = 'status success';
|
||||||
|
statusBox.innerHTML = `<strong>Decryption Complete!</strong><br>File successfully decrypted using supplied key pad.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
statusBox.style.display = 'block';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user