Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Valen-H authored Mar 31, 2018
1 parent dda702f commit 91d15df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions caesar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
String.prototype.map = Array.prototype.map;

const fs = require('fs'),
events = require('events'),
Expand Down Expand Up @@ -91,9 +92,9 @@ class Caesar extends Mix(events.EventEmitter, String, Array) {
if (!value || !key) {
return value;
}
return (value = Buffer.from(value)).map(chunk => {
return (value = Buffer.from(value)).map((chunk, index, array) => {
if (wheel === HEX) return chunk + key * 1;
if (wheel === ASCII || (safe && wheel.indexOf(chunk) < 0) || (wheel.length == 1 && wheel[0] == chunk)) return String.fromCharCode(chunk.charCodeAt(0) + key * 1);
if (wheel === ASCII || (safe && wheel.indexOf(chunk) < 0) || (wheel.length == 1 && wheel[0] == chunk)) return Buffer.from(String.fromCharCode(array.toString().charCodeAt(index) + key * 1))[0];
if (wheel.indexOf(chunk) >= 0) return wheel[wheel.indexOf(chunk) + key * 1];
return chunk;
});
Expand All @@ -102,9 +103,9 @@ class Caesar extends Mix(events.EventEmitter, String, Array) {
if (!value || !key) {
return value;
}
return (value = Buffer.from(value)).map(chunk => {
return (value = Buffer.from(value)).map((chunk, index, array) => {
if (wheel === HEX) return chunk - key;
if (wheel === ASCII || (safe && wheel.indexOf(chunk) < 0) || (wheel.length == 1 && wheel[0] == chunk)) return String.fromCharCode(chunk.charCodeAt(0) - key);
if (wheel === ASCII || (safe && wheel.indexOf(chunk) < 0) || (wheel.length == 1 && wheel[0] == chunk)) return Buffer.from(String.fromCharCode(array.toString().charCodeAt(index) - key))[0];
if (wheel.indexOf(chunk) >= 0) return wheel[wheel.indexOf(chunk) - key];
return chunk;
});
Expand Down Expand Up @@ -145,6 +146,9 @@ class Caesar extends Mix(events.EventEmitter, String, Array) {
return this;
}
toString() {
return this.value.toString();
}
get buffer() {
return this.value;
}
get [Symbol.toStringTag]() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "caesar",
"version": "1.1.0",
"version": "1.1.1",
"description": "A file encryptor with caesar cipher algorithm.",
"main": "caesar.js",
"scripts": {
Expand Down

0 comments on commit 91d15df

Please sign in to comment.