ciphers-data.js v1.0.7
Installation
Go to root directory of your node project and run the following command:
npm i ciphers-data.js
Then in your node_modules folder appear new package
Using
Atbash
Encoding/Decoding with
encode()
anddecode()
const { Atbash } = require('ciphers-data.js') const message = Atbash.encode('ABC') const decodeMessage = Atbash.decode('ZYX') console.log(message) //ZYX console.log(decodeMessage) //ABC
Autokey
It's polyalphabetic substitution cipher, basic on Vigenere cipher
Encoding with
encoded()
Both parameters of function will be uppercasing, key will be writing to the array whose length is equal pain text length. Rest elements in this array will be completing by characters of plain text.
const { Autokey } = require('ciphers-data.js') const message = Autokey.encode('ola', 'dogandcat') console.log(message) //RZG
Decoding with
decode()
Key must be the same as in encoding.
const { Autokey } = require('ciphers-data.js') const message = Autokey.decode('rzg', 'dogandcat') console.log(message) //OLA
Porta
This is a polyalphabetic substitution cipher basically uses 13 pair of letters saved in special matrix
Encoding with
encode()
Porta.encode(<plain text>, <key>)
Example:
const {Porta} = require('ciphers-data.js') const message = Porta.encode('roses are red', 'GARDEN') console.log(message) //BBKSDTBRJSS
Decoding with
decode()
Porta.decode(<encoded text>, <key>)
Example:
const {Porta} = require('ciphers-data.js') const message = Porta.decode('BBKSDTBRJSS', 'GARDEN') console.log(message) //ROSESARERED
Playfair cipher
- First of all, you must import package in your .js file:
const { Playfair } = require('ciphers-data.js')
Using
encode()
function.You can use it if you want change plain text into encoded playfair sentence. Function needs two arguments
encode(<plain text>, <key>) {...}
key is a uppercased by algorithm string which is using to encode setence with written in 5x5 matrix modified alphabet.
Example:
const { Playfair } = require('ciphers-data.js') const message = Playfair.encode('roses are red, violets are','blue') // ^plain text^ ^key^ console.log(message) // TMYGTESUSUCWKIUAPTUTUY
Using
decode()
function.You can use it whether you want decode text encoded in playfair cipher
decode(<encoded text>,<key>)
key must be the same as was in encodeing
Example:
const { Playfair } = require('ciphers-data.js') const message = Playfair.decode('TMYGTESUSUCWKIUAPTUTUY', 'blue') // ^encoded text^ ^key^ console.log(message) //ROSESAREREDVIOLETSAREX
As you can see algorith added
X
on the end of string, because when length of your plain text isn't even it's necessary to encoding.
Caesar cipher
It's one of basic ciphers using swaping letters in string, import modules which is obligate to encoding, deconding and findingKey is the same like in Playfair cipher. But in this implementation program is using ASCII char codes from 40 to 126 to encoding and decoding string.
```js const { Caesar } = require('ciphers-data.js') ```
Encoding string with
encode()
:Key must be integer (not minus)
Example:
const { Caesar } = require('ciphers-data.js') const message = Caesar.encode('hello world', 12) console.log(message) //tqxx{-{~xp
Decoding string with
decode()
Key must be the same as at encoding
Example:
const { Caesar } = require('ciphers-data.js') const message = Caesar.decode('tqxx{-{~xp', 12) console.log(message) //hello world
Finding key with
findKey()
You need plainText, and encoded test
const { Caesar } = require('ciphers-data.js') const key = Caesar.findKey('hello world', 'tqxx{-{~xp') console.log(key) // [12, 12, 12, 12, 12, 12, 12, 12, 12, 12]
Function returns keys of all swaping characters in string.
Solitaire
Original destiny of this cipher was non-computer cryptography but as decoding information by pencil and paper could be non fast, there's a function for encode and decode with key. Key must have the same length such as plain text.
Encoding with
encode()
const { Solitaire } = require('ciphers-data.js') const message = Solitaire.encode('ABCDE', 'FGHIJ') //^plainText, key^// console.log(message) //GIKMO
Decoding with
decode()
const { Solitaire } = require('ciphers-data.js') const message = Solitaire.decode('GIKMO', 'FGHIJ') //^plainText, key^// console.log(message) //ABCDE
Package is in developing mode.