Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 27 additions & 323 deletions README.md

Large diffs are not rendered by default.

Binary file added img/encode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/encode1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/encodeFinal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12,775 changes: 12,775 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions src/cipher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
//encode and decode ASCII function

const cipher = {
// ...
};
encode: (offset, string) => {
let resultado = "", encode;

if (offset === null || string === null || offset === 0 || string === 0)
throw TypeError("Mensagem inválida");

for (let i = 0; i < string.length; i++) {
if (string.charCodeAt(i) >= 65 && string.charCodeAt(i) <= 90) {
encode = ((string.charCodeAt(i) - 65 + offset) % 26) + 65;
}
resultado += String.fromCharCode(encode)
}
return resultado
},

decode: (offset, string) => {
let resultado = "", decode;

if (offset === null || string === null || offset === 0 || string === 0)
throw TypeError("Mensagem inválida");

for (let i = 0; i < string.length; i++) {
if (string.charCodeAt(i) <= 90 && string.charCodeAt(i) >= 65) {
decode = ((string.charCodeAt(i) - 90 - offset) % 26) + 90;
}
resultado += String.fromCharCode(decode)
}

return resultado
}
}

export default cipher;
47 changes: 43 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Caesar Cipher</title>
<title>Encode</title>
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css" />
</head>

<body>
<div id="root">
<h1>Hello world!</h1>
</div>
<header id="root">
<h1>Encode</h1>
</header>
<main>
<h2>Somos um gerador de senhas para login, utilizando um método de cifragem de palavras,
<br> garantindo assim, mais segurança em seus perfis na web.
</h2>

<section>
<p>Criar uma senha segura é apenas um dos passos para se proteger e manter seus dados privados e bem longe dos
hackers. <br> E nós estamos aqui para te ajudar nisso. É muito simples, aqui vão algumas dicas:</p>
<ul>
<li>Digite sua senha para ser cifrada no primeiro campo de texto</li>
<li>Insira o número da chave para a cifragem</li>
<li>Clique no botão para cifrar sua senha</li>
<li>Guarde sua nova senha em um lugar seguro</li>
</ul>
</section>

<form class="textBox">
<fieldset>
<label for="myText"> Senha decifrada </label>
<input type="text" id="myText" value="">

<label for="codeText"> Senha cifrada </label>
<input type="text" id="codeText" value="">
</fieldset>
</form>
</main>

<section class="buttons">
<input type="number" id="offset" placeholder="CHAVE" min="1">
<button id="cifrar" type="submit">CIFRAR</button>
<button id="decifrar" type="submit">DECIFRAR</button>
</section>

<script src="index.js" type="module"></script>
</body>

</html>
22 changes: 20 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
import cipher from './cipher.js';
import cipher from "./cipher.js";

console.log(cipher);
function cifrar() {
const texto = document.getElementById("myText").value;
const offset = parseInt(document.getElementById("offset").value);
document.getElementById("codeText").value = cipher.encode(offset, texto);

}
const cifrarButton = document.getElementById("cifrar");
cifrarButton.addEventListener("click", cifrar);


function decifrar() {
const decifrado = document.getElementById("codeText").value;
const offset = parseInt(document.getElementById("offset").value);
document.getElementById("myText").value = cipher.decode(offset, decifrado);

}

const decifrarButton = document.getElementById("decifrar");
decifrarButton.addEventListener("click", decifrar);
138 changes: 137 additions & 1 deletion src/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,137 @@
/* css */
html {
margin: 0;
padding: 0;
background-color: #241D40;
}

header {
display: flex;
}

h1 {
color: white;
background-color: #988BC7;
width: 74px;
border-radius: 3px;
font-size: 60px;
margin-top: 40px;
margin-left: 80px;
font-family:"Inter", sans-serif;
font-weight: 700;
}

span {
font-family: "Inter", sans-serif;
color: #a8a8b3;
}

h2 {
color: white;
font-family:"Inter", sans-serif;
font-weight: 400;
font-size: 20px;
text-align: center;
padding: 60px 82px;
}

p {
color: white;
font-family:"Inter", sans-serif;
font-weight: 400;
font-size: 18px;
text-align: center;
padding: 60px 82px;
background-color: #241F33;
padding: 60px 82px;
margin-top: -20px;
}


ul{
font-size: 18px;
color: white;
font-family: "Inter", sans-serif;
margin-bottom: 5px;
background-color: #2D2640;
text-align: center;
padding: 60px 82px;
line-height: 26px;
}

.textBox {
margin-top: 40px;
}

fieldset {
display: flex;
margin: auto;
justify-content: space-between;
width: 60vw;
height: 175px;
align-items: center;
border: none;
flex-direction: column;
flex-wrap: wrap;
}

input[type="text"] {
font-family: "Inter", sans-serif;
font-weight: 600;
font-size: 25px;
color: black;
background-color: #E8E6EF;
width: 350px;
height: 150px;
border: none;
border-radius: 3px;
box-shadow: 0px 4px 4px rgba(60, 64, 67, 0.3);
display: flex;
text-align: center;
}

label {
font-family: "Inter", sans-serif;
font-weight: 500;
font-size: 16px;
color: white;
}

.buttons {
display: flex;
flex-wrap: wrap;
margin: auto;
justify-content: space-between;
width: 326px;
align-content: center;
}


#cifrar, #decifrar, #offset {
font-family: "Inter", sans-serif;
font-weight: 700;
background: #483C67;
font-size: 14px;
width: 100px;
border-radius: 20px;
text-align: center;
border-color: #988BC7;
color: white;
margin-bottom: 130px;
margin-top: 30px;
}

#cifrar:hover{
background: #988BC7;
}

#decifrar:hover{
background: #988BC7;
}

#offset {
height: 45px;
}

input::placeholder{
text-align: center;
}
12 changes: 6 additions & 6 deletions test/cipher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('cipher', () => {
expect(cipher.encode(33, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')).toBe('HIJKLMNOPQRSTUVWXYZABCDEFG');
});

// Hacker edition
/* Hacker edition

// Se quiser adicionar testes para letras minúsculas, descomente o teste
// abaixo.
Expand All @@ -39,7 +39,7 @@ describe('cipher', () => {
//
it('should return " !@" for " !@"', () => {
expect(cipher.encode(33, ' !@')).toBe(' !@');
});
});*/
});

describe('cipher.decode', () => {
Expand All @@ -63,17 +63,17 @@ describe('cipher', () => {

// Se quiser adicionar testes para letras minúsculas, descomente o teste
// abaixo.
//
/*
it('should return "abcdefghijklmnopqrstuvwxyz" for "hijklmnopqrstuvwxyzabcdefg" with offset 33', () => {
expect(cipher.decode(33, 'hijklmnopqrstuvwxyzabcdefg')).toBe('abcdefghijklmnopqrstuvwxyz');
});
});*/

// Se quiser adicionar testes para caracteres não alfabéticos, descomente o
// teste abaixo.
//
/*
it('should return " !@" para " !@"', () => {
expect(cipher.decode(33, ' !@')).toBe(' !@');
});
});*/
});

});