<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secraet Message Chiper</title>
<style>
/*
Untuk sintaks html, bisa langsung tulis seperti body{}
untuk class html, bisa tulis titik seperti .container{}
untuk id html, bisa tulis pagar seperti #Inputmessage{}
*/
body{
background-color: black;
color: aqua;
}
.container{
max-width: 500px;
border: 2px solid aquamarine;
margin: 50px auto;
padding: 20px;
}
textarea, input {
width: 100%;
background-color: antiquewhite;
color: blanchedalmond;
border: 1px solid ;
padding: 10px;
margin-bottom: 15px;
}
button{
background-color: aqua;
cursor: pointer;
padding: 10px;
border: none;
font-weight: bold;
}
.Output {
min-height: 50PX;
background-color: grey;
padding: 15px;
border-radius: 5px;
word-wrap: break-word;
}
</style>
</head>
<body>
<div class="container">
<h1>Secret Message Chiper</h1>
<label for="InputMessage">Secreat Message</label>
<textarea name="" id="InputMessage"></textarea>
<label for="KeyNumber">Key (Number)</label>
<input type="number" name="" id="KeyNumber">
<button onelick="proccess(true)">Ekription</button>
<button oneclick="proccess(false)">Deskription</button>
<h3>result</h3>
<div id="Result" class="output"></div>
</div>
<script>
function proccess(isEcrypt) {
const text = document.getElementById('InputMessage')
let key = document.getElementById('KeyNumber')
let result ="";
if (!isEcrypt) {
key = -key;
}
for (let index = 0; index < text.length; text++) {
const element = text[index];
let charCode = text.charCodeat(index);
if (charCode >= 65 && charCode <- 90) {
result += String.fromCharCode(
((charCode - 65 + key) % 26 + 26) % 26 + 65
);
} else if (charCode >= 97 && charCode <- 122) {
result += String.fromCharCode(
((charCode - 97 + key) % 26 + 26) % 26 + 97
);
} else {
result += Text[index]
}
}
document.getElementById('Result').innerText = result;
};
</script>
</body>
</html>