2.1.0 • Published 5 years ago

@mezgoodle/caesar-and-vigenere-ciphers v2.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Caesar and Vigenere ciphers

Hello everyone! This is the repository of my package on JavaScript "Caesar and Vigenere ciphers"

Table of contents

Motivation

I've always been interested in the topic of data encryption, but I didn't delve deeply into it. So I decided to do it on. At first there was an idea to do a CLI or an Electron application. But later it turned into a package for npm.

Build status

Here you can see build status of continuous integration/continuous deployment:

Node.js Package Build Status pipeline status Build Status npm node-current

Code style

I'm using Codacy for automate my code quality.

Codacy Badge

Dependencies

David

I'm using only jest for testing, but that's enough for unit-testing. You may not install it.

You can see all dependencies from package-lock.json here.

Features

With my package you can encrypt / decrypt text with Caesar and Wiegener algorithms with latin, cyrillic or greek alphabet based on UTF-16.

If you see incorrect work with alphabet, please write an issue.

Installation

First install Node.js. Then:

npm i @mezgoodle/caesar-and-vigenere-ciphers --save

Importing

// Using Node.js `require()`
const { caesarEncrypt, caesarDecrypt, vigenereEncryptText, vigenereDecryptText } = require("@mezgoodle/caesar-and-vigenere-ciphers");

Fast usage

// Latin

console.log(caesarEncrypt("pellentesque", 12, "lat"));
// expected output: bqxxqzfqecgq
console.log(caesarDecrypt("pellentesque", -12, "lat"));
// expected output: bqxxqzfqecgq
console.log(vigenereEncrypt("unopinionated", "express", "lat"));
// expected output: ykdgmfaskpkiv
console.log(vigenereDecrypt("ykdgmfaskpkiv", "express", "lat"));
// expected output: unopinionated

// Cyrillic

console.log(caesarEncrypt("привет", 2, "cyr"));
// expected output: сткдзф
console.log(caesarDecrypt("сткдзф", 2, "cyr"));
// expected output: привет
console.log(vigenereEncrypt("Карл у Клары украл кораллы", "кларнет", "cyr"));
// expected output: Флры а Пэкыы гчхтх хоанрэе
console.log(vigenereDecrypt("Флры а Пэкыы гчхтх хоанрэе", "кларнет", "cyr"));
// expected output: Карл у Клары украл кораллы

// Greek

console.log(caesarEncrypt("αβ", 1, "gre"));
// expected output: βγ
console.log(caesarDecrypt("βγ", 1, "gre"));
// expected output: αβ
console.log(vigenereEncrypt("ΓειΑ", "βι", "gre"));
// expected output: ΔνκΙ
console.log(vigenereDecrypt("ΔνκΙ", "βι", "gre"));
// expected output: ΓειΑ

API

caesarEncrypt( value, amount, type )

NameTypeArgumentDefaultDescription
valuestring<required>nullthe message to encrypt
amountnumber<required>nullthe key to encrypt the message with
typestring<required>nullthe type of language: latin or cyrillic

caesarDecrypt( value, amount, type )

NameTypeArgumentDefaultDescription
valuestring<required>nullthe message to decrypt
amountnumber<required>nullthe key to decrypt the message with
typestring<required>nullthe type of language: latin or cyrillic

vigenereEncrypt( text, key, type )

NameTypeArgumentDefaultDescription
textstring<required>nullthe message to encrypt
keystring<required>nullthe key to encrypt the message with
typestring<required>nullthe type of language: latin or cyrillic

vigenereDecrypt( text, key, type )

NameTypeArgumentDefaultDescription
textstring<required>nullthe message to decrypt
keystring<required>nullthe key to decrypt the message with
typestring<required>nullthe type of language: latin or cyrillic

Code Example

Here you can see small example of Vigenere worker

const worker = (str, key, type, lang) => {
  if (typeof(key) !== 'string' || typeof(str) !== 'string')
    throw Error('Text and Key must be string');
  if (!Object.prototype.hasOwnProperty.call(typeDefine, lang))
    throw Error('Type must be "lat" or "cyr"');
  if (str === null || key === null) throw Error('Message and key should be not empty');
  key = keepLetters(key);
  let result = '',
    keyIndex = 0;
  for (let i = 0; i < str.length; i++) {
    const char = str.charAt(i);
    if (isLetter(char)) {
      const key_el = key.charAt(keyIndex++ % key.length);
      const temp = workerChar(char, key_el, type, lang);
      result += temp;
    } else {
      result += char;
    }
  }
  return result;
};

Tests

Unit-testing with assert and jest:

Early here were screenshots

Number of my tests is more than 50, so I can't just do screenshot :smile:. I give you the link to Travis CI, where you can see all my tests.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

GitHub

MIT © mezgoodle

2.1.0

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.12

5 years ago