From ff12182379f02a2383fa3c171959fbb3db568899 Mon Sep 17 00:00:00 2001 From: devanshu Date: Tue, 7 Oct 2025 02:23:46 +0530 Subject: [PATCH 1/3] Enhance URLEncoderDecoder: strong encoding, improved contrast, added hover arrow --- .../DevAreaTools/URLEncoderDecoder.jsx | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/components/DevAreaTools/URLEncoderDecoder.jsx diff --git a/src/components/DevAreaTools/URLEncoderDecoder.jsx b/src/components/DevAreaTools/URLEncoderDecoder.jsx new file mode 100644 index 0000000..2df8453 --- /dev/null +++ b/src/components/DevAreaTools/URLEncoderDecoder.jsx @@ -0,0 +1,140 @@ +import React, { useState, useEffect } from "react"; +import { FaCopy, FaSyncAlt, FaTrashAlt } from "react-icons/fa"; + +// Simple XOR-based obfuscation with key (optional) +const xorEncrypt = (text, key = 129) => { + return text + .split("") + .map((c) => String.fromCharCode(c.charCodeAt(0) ^ key)) + .join(""); +}; + +const toBase64Url = (str) => { + return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); +}; + +const fromBase64Url = (str) => { + str = str.replace(/-/g, "+").replace(/_/g, "/"); + while (str.length % 4) str += "="; + return atob(str); +}; + +const URLEncoderDecoder = () => { + const [input, setInput] = useState(""); + const [output, setOutput] = useState(""); + const [mode, setMode] = useState("encode"); // "encode" or "decode" + const [auto, setAuto] = useState(true); + + const handleConvert = () => { + try { + if (mode === "encode") { + const encrypted = xorEncrypt(input); + setOutput(toBase64Url(encrypted)); + } else { + const decrypted = xorEncrypt(fromBase64Url(input)); + setOutput(decrypted); + } + } catch (e) { + setOutput("❌ Invalid input"); + } + }; + + const handleCopy = () => navigator.clipboard.writeText(output); + const handleClear = () => { + setInput(""); + setOutput(""); + }; + + useEffect(() => { + if (auto && input.trim() !== "") handleConvert(); + if (!input.trim()) setOutput(""); + }, [input, mode, auto]); + + return ( +
+

+ 🔒 Advanced URL Encoder / Decoder +

+ + {/* Controls */} +
+
+ + +
+ +
+ + +
+
+ + {/* Input */} +