<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Secret Message Chiper</title>
<title>Baim love anin</title>
<style>
/*
Untuk panggil sintaks, langsung ketik nama sintaknya
Untuk panggil class, tambahkan titik diawal nama sintaknya
Untuk panggil id, tambahkan hashtag diawal nama sintaknya
*/
body {
background-color: black;
color: green;
}
.container {
margin: 50px auto;
padding: 20px;
border: 2px solid green;
max-width: 500px;
}
textarea, input {
width: 100%;
background-color: black;
color: white;
border: 1px solid green;
padding: 10px;
margin-bottom: 15px;
}
button {
background-color: green;
cursor: pointer;
padding: 10px;
}
.output{
background-color: grey;
min-height: 50px;
border: 15px solid green;
border-radius: 5px;
color:black;
padding: 15px;
word-wrap: break-word;
}
</style>
</head>
<body>
<div class="container">
<h1>The Secret Message Chiper</h1>
<script>
function process(isEncrypt) {
const text = document.getElementById('inputMessage').value;
const key = parseInt(document.getElementById('KeyNumber').value);
let result = "";
if (isEncrypt){
key = -key;
document.getElementById('result').innerText = key;
}
};
</script>
<label>Secret Message:</label>
<textarea name="" id="inputMessage" placeholder="Text message here..."></textarea>
<label>Key (Number):</label>
<input type="number" name="" id="key" value="1">
<div class="buttons">
<button onclick="process(true)">Enkription</button>
<button onclick="process(false)">Dekription</button>
</div>
<h3>Result:</h3>
<div class="output"></div>
</div>
<script>
function process(isEncrypt) {
const text = document.getElementById('inputMessage').value;
let key =parseInt(document.getElementById('KeyNumber').value);
let result = "";
if (!isEncrypt) {
Key = -Key;
}
for(let index = 0;index < text.length; index++) {
const element = text[index];
let charCode = text.charCodeAt(index);
if(charCode >= 65 && charCode <= 90) {//Huruf Kapital}
result <= String.fronCharCode(
((charCode - 65 + key) % 26 + 26) % 26 + 65
);
}
else if(charCode >= 97 && charCode <= 90) {//Huruf Kapital}
result += String.fronCharCode(
((charCode - 65 + key) % 26 + 26) % 26 + 97
);
} else {
result +<= Text[index];
}
}
document.getElementById('Result').innerText = Result;
};
</script>
</body>
</html>