import React, { useEffect, useState } from "react"; import { AlertOctagon } from "lucide-react"; import { useTranslation, Trans } from "react-i18next"; import BoxMessage from "../../../components/BoxMessage"; import * as styles from "./RotTool.module.scss" import { Helmet } from "react-helmet"; const RotTool = () => { const { t } = useTranslation(); let [input, setInput] = useState(""); let [output, setOutput] = useState(""); let [offset, setOffset] = useState(13); let [reversed, setReversed] = useState(false) let [outOfRangeWarning, setOutOfRangeWarning] = useState(false) useEffect(() => { let actualOffset = offset; if(reversed) actualOffset = -offset; let min = 97; // This is a let max = 122; // This is z let range = max - min; // The length of the alphabet let rotInput = reversed ? output.toLowerCase() : input.toLowerCase(); rotInput = rotInput.split(''); let hasOutOfRange = false; let rotOut = rotInput.map((char) => { let charCode = char.charCodeAt(0); if(charCode > max || charCode < min) { hasOutOfRange = true; return char; } charCode += actualOffset; while(charCode > max) charCode -= range; while(charCode < min) charCode += range; return String.fromCharCode(charCode); }) setOutOfRangeWarning(hasOutOfRange); rotOut = rotOut.join('').toUpperCase(); reversed ? setInput(rotOut) : setOutput(rotOut) }, [input, output, reversed, offset]) return (
{t("tools.cryptography.rot.title")} | {t("site.title")}

{t("tools.cryptography.rot.title")}

xxx, pre:

}} />

{t("tools.cryptography.rot.outOfRangeWarning")} {setOffset(parseInt(e.currentTarget.value))}} className={styles.center} />
) } export default RotTool;