The user wants an encryption/decryption system with multiple cipher algorithms. I'll create a comprehensive, visually stunning single-file HTML application that includes:
Let me create this comprehensive cipher tool with a striking visual design.
I'll create a sophisticated encryption/decryption system with a cyberpunk/terminal aesthetic, featuring multiple cipher algorithms with smooth animations and interactive elements.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CIPHER MATRIX - Encryption System</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Orbitron:wght@400;700;900&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0e14;
--bg-secondary: #0f1419;
--fg: #e6e6e6;
--muted: #4a5568;
--accent: #00ffc8;
--accent-secondary: #ff3366;
--card: rgba(15, 20, 25, 0.8);
--border: rgba(0, 255, 200, 0.15);
--glow: rgba(0, 255, 200, 0.4);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'JetBrains Mono', monospace;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
overflow-x: hidden;
}
.font-display {
font-family: 'Orbitron', sans-serif;
}
/* Animated grid background */
.grid-bg {
position: fixed;
inset: 0;
background-image:
linear-gradient(rgba(0, 255, 200, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 255, 200, 0.03) 1px, transparent 1px);
background-size: 50px 50px;
animation: gridMove 20s linear infinite;
pointer-events: none;
}
@keyframes gridMove {
0% { transform: translate(0, 0); }
100% { transform: translate(50px, 50px); }
}
/* Particle canvas */
#particles {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 0;
}
/* Scanline overlay */
.scanlines {
position: fixed;
inset: 0;
background: repeating-linear-gradient(
0deg,
transparent,
transparent 2px,
rgba(0, 0, 0, 0.1) 2px,
rgba(0, 0, 0, 0.1) 4px
);
pointer-events: none;
z-index: 100;
opacity: 0.3;
}
/* Glow orb */
.glow-orb {
position: fixed;
width: 600px;
height: 600px;
border-radius: 50%;
background: radial-gradient(circle, rgba(0, 255, 200, 0.08) 0%, transparent 70%);
pointer-events: none;
z-index: 0;
}
.glow-orb-1 {
top: -200px;
right: -200px;
animation: float1 15s ease-in-out infinite;
}
.glow-orb-2 {
bottom: -300px;
left: -200px;
background: radial-gradient(circle, rgba(255, 51, 102, 0.06) 0%, transparent 70%);
animation: float2 18s ease-in-out infinite;
}
@keyframes float1 {
0%, 100% { transform: translate(0, 0); }
50% { transform: translate(-50px, 50px); }
}
@keyframes float2 {
0%, 100% { transform: translate(0, 0); }
50% { transform: translate(50px, -50px); }
}
/* Main container */
.main-container {
position: relative;
z-index: 10;
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}
/* Header */
.header {
text-align: center;
margin-bottom: 3rem;
animation: fadeInDown 0.8s ease-out;
}
.header h1 {
font-size: clamp(2rem, 5vw, 3.5rem);
font-weight: 900;
letter-spacing: 0.2em;
background: linear-gradient(135deg, var(--accent) 0%, #00ff88 50%, var(--accent-secondary) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-shadow: 0 0 60px var(--glow);
}
.header .subtitle {
font-size: 0.875rem;
color: var(--muted);
letter-spacing: 0.3em;
margin-top: 0.5rem;
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Cipher selector */
.cipher-selector {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
justify-content: center;
margin-bottom: 2rem;
animation: fadeInUp 0.8s ease-out 0.2s both;
}
.cipher-btn {
padding: 0.75rem 1.5rem;
background: var(--card);
border: 1px solid var(--border);
border-radius: 4px;
color: var(--muted);
font-family: 'JetBrains Mono', monospace;
font-size: 0.75rem;
letter-spacing: 0.1em;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.cipher-btn::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(135deg, var(--accent), transparent);
opacity: 0;
transition: opacity 0.3s ease;
}
.cipher-btn:hover {
border-color: var(--accent);
color: var(--fg);
transform: translateY(-2px);
box-shadow: 0 4px 20px rgba(0, 255, 200, 0.2);
}
.cipher-btn:hover::before {
opacity: 0.1;
}
.cipher-btn.active {
border-color: var(--accent);
color: var(--accent);
background: rgba(0, 255, 200, 0.1);
}
.cipher-btn .cipher-number {
font-size: 0.625rem;
opacity: 0.5;
margin-right: 0.5rem;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Main panel */
.cipher-panel {
display: grid;
grid-template-columns: 1fr;
gap: 2rem;
animation: fadeInUp 0.8s ease-out 0.4s both;
}
@media (min-width: 768px) {
.cipher-panel {
grid-template-columns: 1fr 1fr;
}
}
.panel-section {
background: var(--card);
border: 1px solid var(--border);
border-radius: 8px;
padding: 1.5rem;
backdrop-filter: blur(10px);
transition: all 0.3s ease;
}
.panel-section:hover {
border-color: rgba(0, 255, 200, 0.3);
box-shadow: 0 0 40px rgba(0, 255, 200, 0.05);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--border);
}
.panel-title {
font-size: 0.75rem;
letter-spacing: 0.2em;
color: var(--accent);
text-transform: uppercase;
}
.panel-status {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.625rem;
color: var(--muted);
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.3; }
}
/* Key input section */
.key-section {
margin-bottom: 1.5rem;
padding-bottom: 1.5rem;
border-bottom: 1px solid var(--border);
}
.key-label {
font-size: 0.625rem;
letter-spacing: 0.15em;
color: var(--muted);
margin-bottom: 0.5rem;
display: block;
}
.key-input-wrapper {
display: flex;
gap: 0.5rem;
}
.key-input {
flex: 1;
padding: 0.75rem 1rem;
background: rgba(0, 0, 0, 0.3);
border: 1px solid var(--border);
border-radius: 4px;
color: var(--fg);
font-family: 'JetBrains Mono', monospace;
font-size: 0.875rem;
transition: all 0.3s ease;
}
.key-input:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 20px rgba(0, 255, 200, 0.1);
}
.key-input::placeholder {
color: var(--muted);
}
.key-slider {
width: 100%;
margin-top: 0.75rem;
-webkit-appearance: none;
appearance: none;
height: 4px;
background: var(--border);
border-radius: 2px;
cursor: pointer;
}
.key-slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--accent);
cursor: pointer;
transition: all 0.2s ease;
}
.key-slider::-webkit-slider-thumb:hover {
transform: scale(1.2);
box-shadow: 0 0 10px var(--accent);
}
.slider-value {
text-align: center;
font-size: 0.75rem;
color: var(--accent);
margin-top: 0.5rem;
}
/* Text areas */
.text-area {
width: 100%;
min-height: 200px;
padding: 1rem;
background: rgba(0, 0, 0, 0.3);
border: 1px solid var(--border);
border-radius: 4px;
color: var(--fg);
font-family: 'JetBrains Mono', monospace;
font-size: 0.875rem;
line-height: 1.6;
resize: vertical;
transition: all 0.3s ease;
}
.text-area:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 20px rgba(0, 255, 200, 0.1);
}
.text-area::placeholder {
color: var(--muted);
}
/* Action buttons */
.action-buttons {
display: flex;
gap: 1rem;
margin-top: 1.5rem;
flex-wrap: wrap;
}
.action-btn {
flex: 1;
min-width: 120px;
padding: 1rem 1.5rem;
border: 1px solid var(--accent);
border-radius: 4px;
font-family: 'JetBrains Mono', monospace;
font-size: 0.75rem;
letter-spacing: 0.15em;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.action-btn.primary {
background: var(--accent);
color: var(--bg);
}
.action-btn.primary:hover {
background: transparent;
color: var(--accent);
box-shadow: 0 0 30px rgba(0, 255, 200, 0.3);
}
.action-btn.secondary {
background: transparent;
color: var(--accent-secondary);
border-color: var(--accent-secondary);
}
.action-btn.secondary:hover {
background: var(--accent-secondary);
color: var(--bg);
box-shadow: 0 0 30px rgba(255, 51, 102, 0.3);
}
.action-btn.copy {
background: transparent;
color: var(--muted);
border-color: var(--border);
}
.action-btn.copy:hover {
color: var(--fg);
border-color: var(--fg);
}
/* Cipher info */
.cipher-info {
margin-top: 2rem;
padding: 1.5rem;
background: var(--card);
border: 1px solid var(--border);
border-radius: 8px;
animation: fadeInUp 0.8s ease-out 0.6s both;
}
.cipher-info-header {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 1rem;
}
.cipher-info-icon {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 255, 200, 0.1);
border-radius: 8px;
color: var(--accent);
}
.cipher-info-title {
font-size: 1rem;
font-weight: 700;
color: var(--fg);
}
.cipher-info-desc {
font-size: 0.8rem;
color: var(--muted);
line-height: 1.8;
}
.cipher-strength {
display: flex;
align-items: center;
gap: 0.5rem;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid var(--border);
}
.strength-label {
font-size: 0.625rem;
letter-spacing: 0.15em;
color: var(--muted);
}
.strength-bar {
flex: 1;
height: 4px;
background: var(--border);
border-radius: 2px;
overflow: hidden;
}
.strength-fill {
height: 100%;
border-radius: 2px;
transition: width 0.5s ease, background 0.5s ease;
}
.strength-value {
font-size: 0.625rem;
color: var(--accent);
}
/* Toast notification */
.toast {
position: fixed;
bottom: 2rem;
left: 50%;
transform: translateX(-50%) translateY(100px);
padding: 1rem 2rem;
background: var(--card);
border: 1px solid var(--accent);
border-radius: 4px;
color: var(--accent);
font-size: 0.75rem;
letter-spacing: 0.1em;
z-index: 1000;
opacity: 0;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.toast.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
/* Stats bar */
.stats-bar {
display: flex;
gap: 2rem;
justify-content: center;
margin-top: 2rem;
padding: 1rem;
background: var(--card);
border: 1px solid var(--border);
border-radius: 8px;
animation: fadeInUp 0.8s ease-out 0.8s both;
}
.stat-item {
text-align: center;
}
.stat-value {
font-size: 1.5rem;
font-weight: 700;
color: var(--accent);
font-family: 'Orbitron', sans-serif;
}
.stat-label {
font-size: 0.625rem;
letter-spacing: 0.15em;
color: var(--muted);
margin-top: 0.25rem;
}
/* Responsive adjustments */
@media (max-width: 640px) {
.main-container {
padding: 1rem;
}
.cipher-btn {
padding: 0.5rem 1rem;
font-size: 0.625rem;
}
.panel-section {
padding: 1rem;
}
.text-area {
min-height: 150px;
}
.stats-bar {
flex-wrap: wrap;
gap: 1rem;
}
.stat-item {
flex: 1;
min-width: 80px;
}
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* Focus visible states */
.cipher-btn:focus-visible,
.action-btn:focus-visible,
.key-input:focus-visible,
.text-area:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
</style>
</head>
<body>
<!-- Background effects -->
<div class="grid-bg"></div>
<canvas id="particles"></canvas>
<div class="scanlines"></div>
<div class="glow-orb glow-orb-1"></div>
<div class="glow-orb glow-orb-2"></div>
<main class="main-container">
<!-- Header -->
<header class="header">
<h1 class="font-display">CIPHER MATRIX</h1>
<p class="subtitle">MULTI-ALGORITHM ENCRYPTION SYSTEM</p>
</header>
<!-- Cipher selector -->
<nav class="cipher-selector" role="tablist" aria-label="Cipher algorithms">
<button class="cipher-btn active" data-cipher="caesar" role="tab" aria-selected="true">
<span class="cipher-number">01</span>CAESAR
</button>
<button class="cipher-btn" data-cipher="vigenere" role="tab" aria-selected="false">
<span class="cipher-number">02</span>VIGENERE
</button>
<button class="cipher-btn" data-cipher="xor" role="tab" aria-selected="false">
<span class="cipher-number">03</span>XOR
</button>
<button class="cipher-btn" data-cipher="atbash" role="tab" aria-selected="false">
<span class="cipher-number">04</span>ATBASH
</button>
<button class="cipher-btn" data-cipher="rot13" role="tab" aria-selected="false">
<span class="cipher-number">05</span>ROT13
</button>
<button class="cipher-btn" data-cipher="base64" role="tab" aria-selected="false">
<span class="cipher-number">06</span>BASE64
</button>
<button class="cipher-btn" data-cipher="reverse" role="tab" aria-selected="false">
<span class="cipher-number">07</span>REVERSE
</button>
<button class="cipher-btn" data-cipher="morse" role="tab" aria-selected="false">
<span class="cipher-number">08</span>MORSE
</button>
</nav>
<!-- Main panel -->
<div class="cipher-panel">
<!-- Input section -->
<section class="panel-section">
<div class="panel-header">
<span class="panel-title">Input Data</span>
<div class="panel-status">
<span class="status-dot"></span>
READY
</div>
</div>
<!-- Key section -->
<div class="key-section" id="keySection">
<label class="key-label" id="keyLabel">SHIFT VALUE</label>
<div class="key-input-wrapper">
<input
type="number"
class="key-input"
id="keyInput"
placeholder="Enter shift value..."
min="1"
max="25"
value="3"
aria-describedby="keyLabel"
>
</div>
<input type="range" class="key-slider" id="keySlider" min="1" max="25" value="3">
<div class="slider-value" id="sliderValue">3</div>
</div>
<textarea
class="text-area"
id="inputText"
placeholder="Enter text to encrypt or decrypt..."
aria-label="Input text for encryption/decryption"
></textarea>
<div class="action-buttons">
<button class="action-btn primary" id="encryptBtn" aria-label="Encrypt text">
ENCRYPT
</button>
<button class="action-btn secondary" id="decryptBtn" aria-label="Decrypt text">
DECRYPT
</button>
</div>
</section>
<!-- Output section -->
<section class="panel-section">
<div class="panel-header">
<span class="panel-title">Output Data</span>
<div class="panel-status">
<span class="status-dot"></span>
<span id="outputStatus">WAITING</span>
</div>
</div>
<textarea
class="text-area"
id="outputText"
placeholder="Encrypted/decrypted text will appear here..."
readonly
aria-label="Output text result"
></textarea>
<div class="action-buttons">
<button class="action-btn copy" id="copyBtn" aria-label="Copy output to clipboard">
COPY
</button>
<button class="action-btn copy" id="swapBtn" aria-label="Swap input and output">
SWAP
</button>
<button class="action-btn copy" id="clearBtn" aria-label="Clear all text">
CLEAR
</button>
</div>
</section>
</div>
<!-- Cipher info -->
<section class="cipher-info" id="cipherInfo">
<div class="cipher-info-header">
<div class="cipher-info-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="3"/>
<path d="M12 1v6m0 6v10M1 12h6m6 0h10"/>
</svg>
</div>
<div>
<h3 class="cipher-info-title" id="cipherTitle">Caesar Cipher</h3>
</div>
</div>
<p class="cipher-info-desc" id="cipherDesc">
The Caesar cipher is one of the oldest encryption techniques, named after Julius Caesar.
It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet.
Despite its simplicity, it remains a fundamental building block in cryptography education.
</p>
<div class="cipher-strength">
<span class="strength-label">SECURITY LEVEL</span>
<div class="strength-bar">
<div class="strength-fill" id="strengthFill" style="width: 20%; background: var(--accent-secondary);"></div>
</div>
<span class="strength-value" id="strengthValue">WEAK</span>
</div>
</section>
<!-- Stats bar -->
<div class="stats-bar">
<div class="stat-item">
<div class="stat-value" id="inputLength">0</div>
<div class="stat-label">INPUT CHARS</div>
</div>
<div class="stat-item">
<div class="stat-value" id="outputLength">0</div>
<div class="stat-label">OUTPUT CHARS</div>
</div>
<div class="stat-item">
<div class="stat-value" id="operationCount">0</div>
<div class="stat-label">OPERATIONS</div>
</div>
</div>
</main>
<!-- Toast notification -->
<div class="toast" id="toast">Copied to clipboard</div>
<script>
// Initialize variables first
let currentCipher = 'caesar';
let operationCount = 0;
// Cipher information data
const cipherData = {
caesar: {
title: 'Caesar Cipher',
desc: 'The Caesar cipher is one of the oldest encryption techniques, named after Julius Caesar. It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet. Despite its simplicity, it remains a fundamental building block in cryptography education.',
strength: 20,
strengthLabel: 'WEAK',
keyType: 'number',
keyLabel: 'SHIFT VALUE',
keyPlaceholder: 'Enter shift value...',
keyMin: 1,
keyMax: 25,
keyDefault: 3
},
vigenere: {
title: 'Vigenere Cipher',
desc: 'The Vigenere cipher is a polyalphabetic substitution cipher that uses a keyword to determine varying shift values. It was considered unbreakable for centuries and represents a significant advancement over simple substitution ciphers.',
strength: 50,
strengthLabel: 'MODERATE',
keyType: 'text',
keyLabel: 'KEYWORD',
keyPlaceholder: 'Enter keyword...',
keyDefault: 'SECRET'
},
xor: {
title: 'XOR Cipher',
desc: 'The XOR cipher operates by applying the exclusive OR operation between each byte of the plaintext and a key. Its simplicity and the property that XOR is its own inverse make it popular for simple encryption tasks.',
strength: 40,
strengthLabel: 'MODERATE',
keyType: 'text',
keyLabel: 'XOR KEY',
keyPlaceholder: 'Enter XOR key...',
keyDefault: 'KEY'
},
atbash: {
title: 'Atbash Cipher',
desc: 'The Atbash cipher is a monoalphabetic substitution cipher originally used for the Hebrew alphabet. It replaces each letter with its mirror counterpart (A becomes Z, B becomes Y, etc.). No key is required.',
strength: 10,
strengthLabel: 'VERY WEAK',
keyType: 'none',
keyLabel: '',
keyPlaceholder: '',
keyDefault: ''
},
rot13: {
title: 'ROT13 Cipher',
desc: 'ROT13 is a special case of the Caesar cipher with a fixed shift of 13. Because the alphabet has 26 letters, applying ROT13 twice returns the original text. No key is required as the shift is always 13.',
strength: 15,
strengthLabel: 'VERY WEAK',
keyType: 'none',
keyLabel: '',
keyPlaceholder: '',
keyDefault: ''
},
base64: {
title: 'Base64 Encoding',
desc: 'Base64 is not encryption but an encoding scheme that converts binary data into ASCII text. It uses 64 characters (A-Z, a-z, 0-9, +, /) to represent data. Essential for transmitting binary data over text-based protocols.',
strength: 5,
strengthLabel: 'NOT ENCRYPTED',
keyType: 'none',
keyLabel: '',
keyPlaceholder: '',
keyDefault: ''
},
reverse: {
title: 'Reverse Cipher',
desc: 'The reverse cipher simply reverses the order of characters in the text. While not cryptographically secure, it can be combined with other ciphers to add complexity. No key is required.',
strength: 5,
strengthLabel: 'VERY WEAK',
keyType: 'none',
keyLabel: '',
keyPlaceholder: '',
keyDefault: ''
},
morse: {
title: 'Morse Code',
desc: 'Morse code encodes text as sequences of dots and dashes (short and long signals). Originally developed for telegraph communication, it remains in use today in aviation and amateur radio.',
strength: 5,
strengthLabel: 'NOT ENCRYPTED',
keyType: 'none',
keyLabel: '',
keyPlaceholder: '',
keyDefault: ''
}
};
// Morse code mapping
const morseCode = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..', '0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...',
'8': '---..', '9': '----.', ' ': '/'
};
const reverseMorseCode = {};
for (const [key, value] of Object.entries(morseCode)) {
reverseMorseCode[value] = key;
}
// DOM elements
const cipherBtns = document.querySelectorAll('.cipher-btn');
const inputText = document.getElementById('inputText');
const outputText = document.getElementById('outputText');
const keyInput = document.getElementById('keyInput');
const keySlider = document.getElementById('keySlider');
const keySection = document.getElementById('keySection');
const keyLabel = document.getElementById('keyLabel');
const sliderValue = document.getElementById('sliderValue');
const encryptBtn = document.getElementById('encryptBtn');
const decryptBtn = document.getElementById('decryptBtn');
const copyBtn = document.getElementById('copyBtn');
const swapBtn = document.getElementById('swapBtn');
const clearBtn = document.getElementById('clearBtn');
const toast = document.getElementById('toast');
const outputStatus = document.getElementById('outputStatus');
const cipherTitle = document.getElementById('cipherTitle');
const cipherDesc = document.getElementById('cipherDesc');
const strengthFill = document.getElementById('strengthFill');
const strengthValue = document.getElementById('strengthValue');
const inputLengthEl = document.getElementById('inputLength');
const outputLengthEl = document.getElementById('outputLength');
const operationCountEl = document.getElementById('operationCount');
// Particle animation
const canvas = document.getElementById('particles');
const ctx = canvas.getContext('2d');
let particles = [];
function initCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
particles = [];
const particleCount = Math.min(50, Math.floor(window.innerWidth / 20));
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
size: Math.max(1, Math.random() * 2 + 1),
alpha: Math.random() * 0.5 + 0.1
});
}
}
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach((p, i) => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0) p.x = canvas.width;
if (p.x > canvas.width) p.x = 0;
if (p.y < 0) p.y = canvas.height;
if (p.y > canvas.height) p.y = 0;
ctx.beginPath();
const radius = Math.max(0.5, p.size);
ctx.arc(p.x, p.y, radius, 0, Math.PI * 2);
ctx.fillStyle = `rgba(0, 255, 200, ${Math.max(0.01, p.alpha)})`;
ctx.fill();
// Connect nearby particles
particles.slice(i + 1).forEach(p2 => {
const dx = p.x - p2.x;
const dy = p.y - p2.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 150) {
ctx.beginPath();
ctx.moveTo(p.x, p.y);
ctx.lineTo(p2.x, p2.y);
const lineAlpha = Math.max(0.01, (1 - dist / 150) * 0.15);
ctx.strokeStyle = `rgba(0, 255, 200, ${lineAlpha})`;
ctx.stroke();
}
});
});
requestAnimationFrame(animateParticles);
}
initCanvas();
animateParticles();
window.addEventListener('resize', initCanvas);
// Cipher implementations
const ciphers = {
caesar: {
encrypt: (text, shift) => {
const s = parseInt(shift) || 3;
return text.split('').map(char => {
if (char.match(/[a-z]/i)) {
const base = char === char.toUpperCase() ? 65 : 97;
return String.fromCharCode(((char.charCodeAt(0) - base + s) % 26) + base);
}
return char;
}).join('');
},
decrypt: (text, shift) => {
const s = parseInt(shift) || 3;
return ciphers.caesar.encrypt(text, 26 - s);
}
},
vigenere: {
encrypt: (text, key) => {
if (!key) return text;
key = key.toUpperCase();
let keyIndex = 0;
return text.split('').map(char => {
if (char.match(/[a-z]/i)) {
const base = char === char.toUpperCase() ? 65 : 97;
const shift = key.charCodeAt(keyIndex % key.length) - 65;
keyIndex++;
return String.fromCharCode(((char.charCodeAt(0) - base + shift) % 26) + base);
}
return char;
}).join('');
},
decrypt: (text, key) => {
if (!key) return text;
key = key.toUpperCase();
let keyIndex = 0;
return text.split('').map(char => {
if (char.match(/[a-z]/i)) {
const base = char === char.toUpperCase() ? 65 : 97;
const shift = key.charCodeAt(keyIndex % key.length) - 65;
keyIndex++;
return String.fromCharCode(((char.charCodeAt(0) - base - shift + 26) % 26) + base);
}
return char;
}).join('');
}
},
xor: {
encrypt: (text, key) => {
if (!key) return text;
return text.split('').map((char, i) => {
const charCode = char.charCodeAt(0);
const keyCode = key.charCodeAt(i % key.length);
return String.fromCharCode(charCode ^ keyCode);
}).join('');
},
decrypt: (text, key) => ciphers.xor.encrypt(text, key)
},
atbash: {
encrypt: (text) => {
return text.split('').map(char => {
if (char.match(/[a-z]/i)) {
const base = char === char.toUpperCase() ? 65 : 97;
return String.fromCharCode(25 - (char.charCodeAt(0) - base) + base);
}
return char;
}).join('');
},
decrypt: (text) => ciphers.atbash.encrypt(text)
},
rot13: {
encrypt: (text) => ciphers.caesar.encrypt(text, 13),
decrypt: (text) => ciphers.caesar.encrypt(text, 13)
},
base64: {
encrypt: (text) => {
try {
return btoa(unescape(encodeURIComponent(text)));
} catch (e) {
return btoa(text);
}
},
decrypt: (text) => {
try {
return decodeURIComponent(escape(atob(text)));
} catch (e) {
try {
return atob(text);
} catch (err) {
return 'Invalid Base64 input';
}
}
}
},
reverse: {
encrypt: (text) => text.split('').reverse().join(''),
decrypt: (text) => text.split('').reverse().join('')
},
morse: {
encrypt: (text) => {
return text.toUpperCase().split('').map(char => {
return morseCode[char] || char;
}).join(' ');
},
decrypt: (text) => {
return text.split(' ').map(code => {
return reverseMorseCode[code] || code;
}).join('');
}
}
};
// Update key section based on cipher
function updateKeySection() {
const data = cipherData[currentCipher];
if (data.keyType === 'none') {
keySection.style.display = 'none';
} else {
keySection.style.display = 'block';
keyLabel.textContent = data.keyLabel;
keyInput.placeholder = data.keyPlaceholder;
keyInput.value = data.keyDefault;
if (data.keyType === 'number') {
keyInput.type = 'number';
keyInput.min = data.keyMin;
keyInput.max = data.keyMax;
keySlider.style.display = 'block';
sliderValue.style.display = 'block';
keySlider.min = data.keyMin;
keySlider.max = data.keyMax;
keySlider.value = data.keyDefault;
sliderValue.textContent = data.keyDefault;
} else {
keyInput.type = 'text';
keySlider.style.display = 'none';
sliderValue.style.display = 'none';
}
}
// Update info section
cipherTitle.textContent = data.title;
cipherDesc.textContent = data.desc;
strengthFill.style.width = data.strength + '%';
const colors = {
5: 'var(--accent-secondary)',
10: 'var(--accent-secondary)',
15: '#ff6b35',
20: '#ff6b35',
40: '#ffc107',
50: '#00ffc8'
};
strengthFill.style.background = colors[data.strength] || 'var(--accent)';
strengthValue.textContent = data.strengthLabel;
}
// Event listeners
cipherBtns.forEach(btn => {
btn.addEventListener('click', () => {
cipherBtns.forEach(b => {
b.classList.remove('active');
b.setAttribute('aria-selected', 'false');
});
btn.classList.add('active');
btn.setAttribute('aria-selected', 'true');
currentCipher = btn.dataset.cipher;
updateKeySection();
});
});
keySlider.addEventListener('input', (e) => {
keyInput.value = e.target.value;
sliderValue.textContent = e.target.value;
});
keyInput.addEventListener('input', (e) => {
if (cipherData[currentCipher].keyType === 'number') {
const val = Math.min(25, Math.max(1, parseInt(e.target.value) || 1));
keySlider.value = val;
sliderValue.textContent = val;
}
});
encryptBtn.addEventListener('click', () => {
const text = inputText.value;
const key = keyInput.value;
if (!text) {
showToast('Please enter text to encrypt');
return;
}
const result = ciphers[currentCipher].encrypt(text, key);
outputText.value = result;
outputStatus.textContent = 'ENCRYPTED';
operationCount++;
updateStats();
showToast('Text encrypted successfully');
});
decryptBtn.addEventListener('click', () => {
const text = inputText.value;
const key = keyInput.value;
if (!text) {
showToast('Please enter text to decrypt');
return;
}
const result = ciphers[currentCipher].decrypt(text, key);
outputText.value = result;
outputStatus.textContent = 'DECRYPTED';
operationCount++;
updateStats();
showToast('Text decrypted successfully');
});
copyBtn.addEventListener('click', () => {
if (!outputText.value) {
showToast('No output to copy');
return;
}
navigator.clipboard.writeText(outputText.value);
showToast('Copied to clipboard');
});
swapBtn.addEventListener('click', () => {
const temp = inputText.value;
inputText.value = outputText.value;
outputText.value = temp;
updateStats();
showToast('Input and output swapped');
});
clearBtn.addEventListener('click', () => {
inputText.value = '';
outputText.value = '';
outputStatus.textContent = 'WAITING';
updateStats();
showToast('All fields cleared');
});
inputText.addEventListener('input', updateStats);
function updateStats() {
inputLengthEl.textContent = inputText.value.length;
outputLengthEl.textContent = outputText.value.length;
operationCountEl.textContent = operationCount;
}
function showToast(message) {
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 2000);
}
// Keyboard shortcuts
document.addEventListener('keydown', (e) => {
if (e.ctrlKey || e.metaKey) {
if (e.key === 'Enter') {
e.preventDefault();
encryptBtn.click();
} else if (e.shiftKey && e.key === 'Enter') {
e.preventDefault();
decryptBtn.click();
}
}
});
// Initialize
updateKeySection();
updateStats();
</script>
</body>
</html>