Skip to content

Commit 07f3039

Browse files
committed
u
1 parent 62d4e39 commit 07f3039

File tree

2 files changed

+57
-137
lines changed

2 files changed

+57
-137
lines changed

notes/info/text-editor-uc.html

Lines changed: 55 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,150 +1543,74 @@ <h2 style="margin-top: 4px; margin-bottom: 5px; font-size: 20px">
15431543
</script>
15441544

15451545
<button
1546-
onclick="encryptText();"
1546+
onclick="toggleLeetSpeak();"
1547+
id="leetSwitch"
15471548
class="ttClass"
1548-
data-tooltip="(Web Crypto API, AES-GCM) Enter text to encrypt, click Encrypt, then enter a password when
1549-
prompted. A base64 representation of the encrypted data will be
1550-
displayed."
1549+
data-tooltip="Translate regular text to leet speak on first click, and does the reverse on second click."
15511550
>
1552-
🔒 EncryptTxt
1553-
</button>
1554-
1555-
<button
1556-
onclick="decryptText();"
1557-
class="ttClass"
1558-
data-tooltip="Enter text to decrypt, click Decrypt and then when
1559-
prompted, enter the same password as used for
1560-
encrypting."
1561-
>
1562-
🔓 DecryptTxt
1551+
📔 1337
15631552
</button>
15641553

15651554
<script>
1566-
// https://github.com/bradyjoslin/webcrypto-example
1567-
1568-
// possible alternative?: https://github.com/paulgreg/crypttool
1569-
1570-
// for large strings, use this from https://stackoverflow.com/a/49124600
1571-
const buff_to_base64 = (buff) =>
1572-
btoa(
1573-
new Uint8Array(buff).reduce(
1574-
(data, byte) => data + String.fromCharCode(byte),
1575-
""
1576-
)
1577-
);
1578-
1579-
const base64_to_buf = (b64) =>
1580-
Uint8Array.from(atob(b64), (c) => c.charCodeAt(null));
1581-
1582-
const enc = new TextEncoder();
1583-
const dec = new TextDecoder();
1584-
1585-
async function encryptText() {
1586-
// const data = window.document.getElementById("data").value;
1587-
const data = document.getElementById("textMainArea").value;
1588-
// let encryptedDataOut = window.document.getElementById("encryptedData");
1589-
let encryptedDataOut =
1590-
window.document.getElementById("textMainArea");
1591-
// Prompt for the password
1592-
1593-
const password = window.prompt("Password");
1594-
const encryptedData = await encryptData(data, password);
1595-
encryptedDataOut.value = encryptedData;
1596-
}
1597-
1598-
async function decryptText() {
1599-
// Prompt for the password
1555+
var leetspeak_timesClicked = 0;
1556+
1557+
function leetSpeak() {
1558+
const textArea = document.getElementById("textMainArea");
1559+
let text = textArea.value.toLowerCase();
1560+
1561+
const leetMap = {
1562+
a: "4",
1563+
e: "3",
1564+
l: "1",
1565+
o: "0",
1566+
s: "5",
1567+
t: "7",
1568+
// Add more mappings for lowercase letters here
1569+
};
16001570

1601-
const password = window.prompt("Password");
1602-
// const encryptedData = window.document.getElementById("encryptedData").value;
1603-
const encryptedData =
1604-
window.document.getElementById("textMainArea").value;
1605-
// let decryptedDataOut = window.document.getElementById("decrypted");
1606-
let decryptedDataOut =
1607-
window.document.getElementById("textMainArea");
1608-
const decryptedData = await decryptData(encryptedData, password);
1609-
decryptedDataOut.value = decryptedData || "Decryption failed";
1571+
const leetText = text.replace(/[a-z]/g, function (char) {
1572+
return leetMap[char] || char;
1573+
});
16101574

1611-
// added this to scroll back up, but only after prompt has been given, needed for mobile
1612-
scrollToTopFully();
1575+
textArea.value = leetText;
16131576
}
16141577

1615-
const getPasswordKey = (password) =>
1616-
window.crypto.subtle.importKey(
1617-
"raw",
1618-
enc.encode(password),
1619-
"PBKDF2",
1620-
false,
1621-
["deriveKey"]
1622-
);
1623-
1624-
const deriveKey = (passwordKey, salt, keyUsage) =>
1625-
window.crypto.subtle.deriveKey(
1626-
{
1627-
name: "PBKDF2",
1628-
salt: salt,
1629-
iterations: 250000,
1630-
hash: "SHA-256",
1631-
},
1632-
passwordKey,
1633-
{ name: "AES-GCM", length: 256 },
1634-
false,
1635-
keyUsage
1636-
);
1578+
function englishText() {
1579+
const textArea = document.getElementById("textMainArea");
1580+
let text = textArea.value;
1581+
1582+
const leetMap = {
1583+
4: "a",
1584+
3: "e",
1585+
1: "l",
1586+
0: "o",
1587+
5: "s",
1588+
7: "t",
1589+
// Add more mappings for leetspeak to English here
1590+
};
16371591

1638-
async function encryptData(secretData, password) {
1639-
try {
1640-
const salt = window.crypto.getRandomValues(new Uint8Array(16));
1641-
const iv = window.crypto.getRandomValues(new Uint8Array(12));
1642-
const passwordKey = await getPasswordKey(password);
1643-
const aesKey = await deriveKey(passwordKey, salt, ["encrypt"]);
1644-
const encryptedContent = await window.crypto.subtle.encrypt(
1645-
{
1646-
name: "AES-GCM",
1647-
iv: iv,
1648-
},
1649-
aesKey,
1650-
enc.encode(secretData)
1651-
);
1592+
const englishText = text.replace(/[0-9]/g, function (char) {
1593+
return leetMap[char] || char;
1594+
});
16521595

1653-
const encryptedContentArr = new Uint8Array(encryptedContent);
1654-
let buff = new Uint8Array(
1655-
salt.byteLength +
1656-
iv.byteLength +
1657-
encryptedContentArr.byteLength
1658-
);
1659-
buff.set(salt, 0);
1660-
buff.set(iv, salt.byteLength);
1661-
buff.set(encryptedContentArr, salt.byteLength + iv.byteLength);
1662-
const base64Buff = buff_to_base64(buff);
1663-
return base64Buff;
1664-
} catch (e) {
1665-
console.log(`Error - ${e}`);
1666-
return "";
1667-
}
1596+
textArea.value = englishText;
16681597
}
16691598

1670-
async function decryptData(encryptedData, password) {
1671-
try {
1672-
const encryptedDataBuff = base64_to_buf(encryptedData);
1673-
const salt = encryptedDataBuff.slice(0, 16);
1674-
const iv = encryptedDataBuff.slice(16, 16 + 12);
1675-
const data = encryptedDataBuff.slice(16 + 12);
1676-
const passwordKey = await getPasswordKey(password);
1677-
const aesKey = await deriveKey(passwordKey, salt, ["decrypt"]);
1678-
const decryptedContent = await window.crypto.subtle.decrypt(
1679-
{
1680-
name: "AES-GCM",
1681-
iv: iv,
1682-
},
1683-
aesKey,
1684-
data
1685-
);
1686-
return dec.decode(decryptedContent);
1687-
} catch (e) {
1688-
console.log(`Error - ${e}`);
1689-
return "";
1599+
function toggleLeetSpeak() {
1600+
leetspeak_timesClicked++;
1601+
if (leetspeak_timesClicked % 2 == 0) {
1602+
englishText();
1603+
//
1604+
document.getElementById("leetSwitch").innerHTML = "📔 1337";
1605+
//
1606+
} else {
1607+
leetSpeak();
1608+
//
1609+
document.getElementById("leetSwitch").innerHTML = "unleet";
1610+
// ltr switch
1611+
document.getElementById("textMainArea").style.direction = "ltr";
1612+
//
1613+
//
16901614
}
16911615
}
16921616
</script>

0 commit comments

Comments
 (0)