npx standard --fix

This commit is contained in:
cclauss
2020-05-03 09:05:12 +02:00
parent e62ad2f73e
commit 856dc2f63c
47 changed files with 2240 additions and 2371 deletions

View File

@ -3,8 +3,8 @@
* @param {String} character - character to check
* @return {object} An array with the character or null if isn't a letter
*/
function isLetter(str) {
return str.length === 1 && str.match(/[a-zA-Z]/i);
function isLetter (str) {
return str.length === 1 && str.match(/[a-zA-Z]/i)
}
/**
@ -12,12 +12,12 @@ function isLetter(str) {
* @param {String} character - character to check
* @return {Boolean} result of the checking
*/
function isUpperCase(character){
function isUpperCase (character) {
if (character == character.toUpperCase()) {
return true;
return true
}
if (character == character.toLowerCase()){
return false;
if (character == character.toLowerCase()) {
return false
}
}
@ -27,25 +27,23 @@ function isUpperCase(character){
* @param {String} key - key for encrypt
* @return {String} result - encrypted string
*/
function encrypt(message, key)
{
let result = "";
function encrypt (message, key) {
let result = ''
for (let i = 0, j = 0; i < message.length; i++) {
let c = message.charAt(i);
if (isLetter(c)){
if(isUpperCase(c)) {
result += String.fromCharCode((c.charCodeAt(0) + key.toUpperCase().charCodeAt(j) - 2 * 65) % 26 + 65); // A: 65
const c = message.charAt(i)
if (isLetter(c)) {
if (isUpperCase(c)) {
result += String.fromCharCode((c.charCodeAt(0) + key.toUpperCase().charCodeAt(j) - 2 * 65) % 26 + 65) // A: 65
} else {
result += String.fromCharCode((c.charCodeAt(0) + key.toLowerCase().charCodeAt(j) - 2 * 97) % 26 + 97); // a: 97
result += String.fromCharCode((c.charCodeAt(0) + key.toLowerCase().charCodeAt(j) - 2 * 97) % 26 + 97) // a: 97
}
} else {
result+=c;
result += c
}
j = ++j % key.length;
j = ++j % key.length
}
return result;
return result
}
/**
@ -54,28 +52,27 @@ function encrypt(message, key)
* @param {String} key - key for decrypt
* @return {String} result - decrypted string
*/
function decrypt(message, key)
{
let result ="";
function decrypt (message, key) {
let result = ''
for(let i = 0, j = 0; i < message.length; i++){
let c = message.charAt(i);
if (isLetter(c)){
if(isUpperCase(c)) {
result += String.fromCharCode(90-(25-(c.charCodeAt(0)-key.toUpperCase().charCodeAt(j)))%26);
for (let i = 0, j = 0; i < message.length; i++) {
const c = message.charAt(i)
if (isLetter(c)) {
if (isUpperCase(c)) {
result += String.fromCharCode(90 - (25 - (c.charCodeAt(0) - key.toUpperCase().charCodeAt(j))) % 26)
} else {
result += String.fromCharCode(122-(25-(c.charCodeAt(0)-key.toLowerCase().charCodeAt(j)))%26);
result += String.fromCharCode(122 - (25 - (c.charCodeAt(0) - key.toLowerCase().charCodeAt(j))) % 26)
}
} else {
result+=c;
result += c
}
j = ++j % key.length;
j = ++j % key.length
}
return result;
return result
}
let messageEncrypt = encrypt('Hello World!', 'code');
console.log(messageEncrypt); // "Jhpnr Yrvng!"
const messageEncrypt = encrypt('Hello World!', 'code')
console.log(messageEncrypt) // "Jhpnr Yrvng!"
let messageDecrypt = decrypt('Jsopq Zstzg!', 'code');
console.log(messageDecrypt); // "Hello World!"
const messageDecrypt = decrypt('Jsopq Zstzg!', 'code')
console.log(messageDecrypt) // "Hello World!"