diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..fbb5dc3 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,29 @@ +{ + "parserOptions": { + "ecmaVersion": 6 + }, + "rules": { + "keyword-spacing": 1, + "space-before-function-paren": [1, "never"], + "eqeqeq": 1, + "space-infix-ops": 1, + "comma-spacing": 1, + "brace-style": 1, + "no-multiple-empty-lines": 1, + "camelcase": 1, + "func-call-spacing": 1, + "key-spacing": 1, + "semi": 1, + "no-floating-decimal": 1, + "no-multi-spaces": 1, + "object-property-newline": 1, + "padded-blocks": [1, "never"], + "space-before-blocks": 1, + "space-in-parens": 1, + "spaced-comment": 1, + "quotes": [1, "single"], + "id-length": [1, { "exceptions": ["i", "j", "x"] }], + "indent": [1, 2], + "no-array-constructor": 1 + } +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..c54679a --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + Cipher Cesar + + +

The first word is encrypted and the second word is decrypted

+ + + \ No newline at end of file diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..618aa2d --- /dev/null +++ b/js/app.js @@ -0,0 +1,53 @@ +var word = prompt('Write a word to encrypt'); +function cipher(string) { +// Creamos una variable vacia para almacenar el string encriptado// + var newString = ''; + // Iteramos cada caracter del string + for (var i = 0; i < word.length; i++) { + // Almacenamos el codigo ASCII de cada caracter + var encrypter = word.charCodeAt(i); + // Verificamos si las letras son mayusculas. + if (encrypter >= 65 && encrypter <= 90) { + // Aplicamos la formula para obtener el codigo ASCII + var letters = (encrypter - 65 + 33) % 26 + 65; + // Convertimos el codigo ASCII en letra encriptada y lo unimos al string vacío + newString += String.fromCharCode(letters); + } else if (encrypter >= 97 && encrypter <= 122) { // Repetimos el procedimiento si son minusculas. + var lettersTwo = (encrypter - 97 + 33) % 26 + 97; + newString += String.fromCharCode(lettersTwo); + } else if (typeof string !== String) { // Verificamos que el usuario no ingrese un numero o campo vacio + alert('You have not entered a word'); + } + } + return newString; +} +// Llamamos a la funcion +document.write(cipher('word')); + +var word = prompt('Write a word to decode'); +function decipher(string) { + // Creamos una variable vacia para almacenar el string encriptado + var newString = ' '; + // Iteramos cada caracter del string + for (var i = 0; i < word.length; i++) { + // Almacenamos el codigo ASCII de cada caracter + var encrypter = word.charCodeAt(i); + // Verificamos si las letras son mayusculas. + if (encrypter >= 65 && encrypter <= 90) { + // Aplicamos la formula para obtener el codigo ASCII + var letters = (encrypter - 65 - 33) % 26 + 65; + // Convertimos el codigo ASCII en letra encriptada y lo unimos al string vacío + newString += String.fromCharCode(letters); + } else if (encrypter >= 97 && encrypter <= 122) {// Repetimos el procedimiento si son minusculas. + var lettersTwo = (encrypter - 97 - 33) % 26 + 97; + newString += String.fromCharCode(lettersTwo); + } else if (typeof string !== String) {// Verificamos que el usuario no ingrese un numero o campo vacio + alert('You have not entered a word'); + } + } + return newString; +} +// Llamamos a la funcion +document.write(decipher('word')); + +