Skip to content

Instantly share code, notes, and snippets.

@bbstilson
Created March 16, 2018 21:02
Show Gist options
  • Save bbstilson/d11fa16f7d8f313836512b0cfcb9394d to your computer and use it in GitHub Desktop.
Save bbstilson/d11fa16f7d8f313836512b0cfcb9394d to your computer and use it in GitHub Desktop.
Encrypted homework
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Encrypt</title>
</head>
<body>
<div>
<p>Text to encrypt:</p>
<input id="text" type="text" placeholder="Plain text here" />
</div>
<div>
<p>Choose encryption algorithm:</p>
<select name="algorithms" id="algorithms">
<option value="SHA1">SHA1</option>
<option value="SHA256">SHA256</option>
<option value="SHA512">SHA512</option>
</select>
<input id="submit" type="submit" value="Encrypt" />
</div>
<div id="encrypted" />
<script>
const algorithmEl = document.getElementById('algorithms');
const textEl = document.getElementById('text');
const encryptedEl = document.getElementById('encrypted');
document.getElementById('submit').addEventListener('click', () => {
const text = textEl.value;
const algorithm = algorithmEl.value;
if (text.length > 0) {
fetch(`http://localhost:1337/encrypt?algorithm=${algorithm}&string=${text}`)
.then((res) => res.json())
.then((json) => {
const { statusCode, message } = json;
encryptedEl.innerHTML = `
<p>Encrypted:</p>
<p>${message}</p>
`;
})
.catch((err) => {
encryptedEl.innerHTML = `
<p>There was an error. Please try again soon.</p>
`;
});
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment