diff --git a/pyproject.toml b/pyproject.toml index 14190d8..8cc4c25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,3 +6,5 @@ requires-python = ">=3.10" [tool.unittest] # No special configuration needed, unittest is standard library +[tool.vercel] +entrypoint = "math.Happy-Number.Happy-Number:app" diff --git a/utilities/Caesar-cipher/caesar_ciphar.py b/utilities/Caesar-cipher/caesar_ciphar.py new file mode 100644 index 0000000..d09ab6c --- /dev/null +++ b/utilities/Caesar-cipher/caesar_ciphar.py @@ -0,0 +1,63 @@ +print("š Caesar Cipher Encoder & Decoder š") +print("Encrypt and decrypt messages using Caesar Cipher\n") + + +def encrypt(text, shift): + + result = "" + + for char in text: + + if char.isupper(): + result += chr((ord(char) - 65 + shift) % 26 + 65) + + elif char.islower(): + result += chr((ord(char) - 97 + shift) % 26 + 97) + + else: + result += char + + return result + + +def decrypt(text, shift): + + return encrypt(text, -shift) + + +while True: + + print("=" * 50) + print("šÆ Choose an option:") + print("1ļøā£ Encrypt Text") + print("2ļøā£ Decrypt Text") + print("3ļøā£ Exit") + print("=" * 50) + + choice = input("\nā”ļø Enter your choice (1-3): ") + + if choice == '1': + + text = input("\nš Enter text to encrypt: ") + shift = int(input("š Enter shift value: ")) + + encrypted = encrypt(text, shift) + + print(f"\nš Encrypted Text: {encrypted}\n") + + elif choice == '2': + + text = input("\nšØ Enter text to decrypt: ") + shift = int(input("š Enter shift value: ")) + + decrypted = decrypt(text, shift) + + print(f"\nš Decrypted Text: {decrypted}\n") + + elif choice == '3': + + print("\nš Thanks for using Caesar Cipher! Goodbye!\n") + break + + else: + print("\nā Invalid choice! Please select 1-3.\n") \ No newline at end of file diff --git a/web-app/js/projects.js b/web-app/js/projects.js index 04ba8fd..6150066 100644 --- a/web-app/js/projects.js +++ b/web-app/js/projects.js @@ -39,6 +39,7 @@ function getProjectHTML(projectName) { '2048-game': () => get2048GameHTML(), 'productive-pet': () => getProductivePetHTML(), 'color-palette': () => getColorPaletteHTML(), + 'caesar-cipher': () => getCaesarCipherHTML(), }; try { @@ -3276,7 +3277,8 @@ function initializeProject(projectName) { 'simon-says': 'initSimonSays', '2048-game': 'init2048Game', 'color-palette': 'initColorPalette', - 'math-quiz': 'initMathQuiz' + 'math-quiz': 'initMathQuiz', + 'caesar-cipher': 'initCaesarCipher' }; const initializerName = initializers[projectName]; diff --git a/web-app/js/projects/ceasar-ciphar.js b/web-app/js/projects/ceasar-ciphar.js new file mode 100644 index 0000000..21e449a --- /dev/null +++ b/web-app/js/projects/ceasar-ciphar.js @@ -0,0 +1,412 @@ +function getCaesarCipherHTML() { + return ` +
Encrypt and decrypt messages using Caesar Cipher
+ +Your result will appear here...
+Your result will appear here...
'; + copyBtn.style.display = 'none'; + goBtn.textContent = isEncrypt ? 'š Encrypt Message' : 'š Decrypt Message'; + } + + function syncSlider(val) { + const clamped = Math.min(25, Math.max(1, val)); + shiftNumber.value = clamped; + shiftSlide.value = clamped; + showPreview(clamped); + } + + function showError(msg) { + outputBox.innerHTML = `ā ${msg}
`; + copyBtn.style.display = 'none'; + } + + function showResult(text) { + outputBox.innerHTML = ''; + const p = document.createElement('p'); + p.className = 'result-text'; + p.textContent = text; + outputBox.appendChild(p); + copyBtn.style.display = 'inline-block'; + copyBtn.dataset.result = text; + } + + encryptRadio.addEventListener('change', () => setMode(true)); + decryptRadio.addEventListener('change', () => setMode(false)); + + shiftSlide.addEventListener('input', () => syncSlider(parseInt(shiftSlide.value))); + shiftNumber.addEventListener('input', () => syncSlider(parseInt(shiftNumber.value))); + + goBtn.addEventListener('click', () => { + const text = textBox.value; + const shift = parseInt(shiftNumber.value); + + if (!text.trim()) return showError('Please enter some text first!'); + if (isNaN(shift) || shift < 1 || shift > 25) return showError('Please enter a shift value between 1 and 25!'); + + const result = encryptRadio.checked ? encryptText(text, shift) : decryptText(text, shift); + showResult(result); + }); + + clearBtn.addEventListener('click', () => { + textBox.value = ''; + outputBox.innerHTML = 'Your result will appear here...
'; + copyBtn.style.display = 'none'; + }); + + copyBtn.addEventListener('click', () => { + navigator.clipboard.writeText(copyBtn.dataset.result).then(() => { + const original = copyBtn.textContent; + copyBtn.textContent = 'ā Copied!'; + setTimeout(() => copyBtn.textContent = original, 1500); + }); + }); + + showPreview(3); +} \ No newline at end of file