import React, {useContext} from 'react';
import {Divider, SegmentGroup, StatisticLabel, StatisticValue} from "semantic-ui-react";
import {Link, Route, Routes} from "react-router-dom";
import "../static/wrolpi.css";
import {decryptOTP, encryptOTP} from "../api";
import {humanFileSize, mimetypeColor, PageContainer, toLocaleString, useTitle} from "./Common";
import {ThemeContext} from "../contexts/contexts";
import {Button, Header, Loader, Segment, Statistic, StatisticGroup, TextArea} from "./Theme";
import {useStatistics} from "../hooks/customHooks";
class Encrypt extends React.Component {
constructor(props) {
super(props);
this.state = {
otp: '', plaintext: '', ciphertext: '',
}
}
handleSubmit = async (e) => {
e.preventDefault();
try {
let {otp, plaintext, ciphertext} = await encryptOTP(this.state.otp, this.state.plaintext);
this.setState({otp, plaintext, ciphertext});
} catch (e) {
console.error(e);
}
}
handleInputChange = async (event, {name, value}) => {
this.setState({[name]: value});
}
render() {
return <>
Key
Plaintext
Ciphertext
{this.state.ciphertext || 'Enter your message above'}
>
}
}
class Decrypt extends React.Component {
constructor(props) {
super(props);
this.state = {
otp: '', plaintext: '', ciphertext: '',
}
}
handleSubmit = async (e) => {
e.preventDefault();
try {
let {otp, plaintext, ciphertext} = await decryptOTP(this.state.otp, this.state.ciphertext);
this.setState({otp, plaintext, ciphertext});
} catch (e) {
console.error(e);
}
}
handleInputChange = async (event, {name, value}) => {
this.setState({[name]: value});
}
render() {
return <>
Key
Ciphertext
Plaintext
{this.state.plaintext || 'Enter the encrypted message above'}
>
}
}
function OTP() {
useTitle('One Time Pad');
const {t} = useContext(ThemeContext);
let newPadURL = `http://${window.location.host}/api/otp/html`;
let cheatSheetURL = `${process.env.PUBLIC_URL}/one-time-pad-cheat-sheet.pdf`;
return <>
These messages are never stored and cannot be retrieved.
Failed to fetch statistics