Skip to content

Commit

Permalink
Merge pull request #19 from vcapretz/feature-refactor-es6
Browse files Browse the repository at this point in the history
refactors to es6 and adds XO linter
  • Loading branch information
rdiego26 authored Jun 19, 2017
2 parents 30d10ed + 81e76e7 commit 04e026c
Show file tree
Hide file tree
Showing 8 changed files with 2,174 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js
node_js:
- "node"
install:
- "npm install -g codecov mocha istanbul"
- "npm install -g codecov mocha istanbul xo"
script:
- "npm test"
- "npm run cover"
Expand Down
70 changes: 70 additions & 0 deletions lib/ciphers/simple-substitution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const generateRandomKey = () => {
const keychars = 'abcdefghijklmnopqrstuvwxyz';

return keychars
.split('')
.sort(() => 0.5 - Math.random())
.join('');
};

module.exports = {

lastKey: '',

/**
* Encrypt string from key
* @param plainText
* @param optionalKey
* @returns {string}
*/
encrypt: (plainText, optionalKey = generateRandomKey()) => {
const _key = optionalKey;
const _regex = /[a-z]/;

if (plainText.length < 1) {
throw Object.assign({}, {
message: 'Blank text!'
});
}

this.lastKey = _key;

return Array.from(plainText)
.map((letter, index) => {
if (!_regex.test(letter)) {
return letter;
}

return _key.charAt(plainText.charCodeAt(index) - 97);
})
.join('');
},

/**
* Decrypt string
* @param cipherText
* @returns {string}
*/
decrypt: cipherText => {
const _key = this.lastKey;
const _cipherText = cipherText.toLowerCase();
const _regex = /[a-z]/;

if (_cipherText.length < 1) {
throw Object.assign({}, {
message: 'Blank text!'
});
}

return Array.from(_cipherText)
.map(letter => {
if (!_regex.test(letter)) {
return letter;
}

return String.fromCharCode(_key.indexOf(letter) + 97);
})
.join('');
}

};
71 changes: 0 additions & 71 deletions lib/ciphers/simpleSubstitution.js

This file was deleted.

15 changes: 5 additions & 10 deletions lib/klefki.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const path = require('path'),
simpleSubstitution = require( path.resolve('lib/ciphers/simpleSubstitution') );

var klefki = {

ciphers: {
simpleSubstitution: simpleSubstitution
}
const simpleSubstitution = require('./ciphers/simple-substitution');

module.exports = {
ciphers: {
simpleSubstitution
}
};

module.exports = klefki;
Loading

0 comments on commit 04e026c

Please sign in to comment.