Rubik cipher
Basic implementation of rubik cipher.
Installation
npm install rubik-cipher --save
Usage
RubikCipherConfig
Configuration object that is passed when creating new RubikCipher
field | type | default | required | explanation |
---|---|---|---|---|
cubeSize | number | 2 | no | How large is the cube (n*n)) |
groupSize | number | 1 | no | By how many chars group the divided string |
fillRest | boolean | true | no | If the rest of cube spaces will be filled or left empty |
fillWithRandom | boolean | false | no | If the spaces will be filled by char 'x' or with random character |
JavaScript
Creation
const RubikCipher = ; // Creates cube with default parametersconst defaultCube = 'hello world!'; // Creates cube with RubikCipherConfigconst configCube = 'hello world!' cubeSize: 2 groupSize: 1 fillRest: true fillWithRandom: true; // Creates and decodes cube with selected key config// keyCube.Text should be 'testxxxxxxxxxxxxxxxxxxxx'const keyCube = 'xsxtxtxxxxxexxxxxxxxxxxx' '2+1+1+0+B111 L012 B113 D111 B013';
Values
// By using default parameters the fillRest is true, so the rest of the string after typed text is char 'x' // example: 'hello world!xxxxxxxxxxxx'const currentText = cubeText; // Generated combination that follows pattern: 'B111 L012 B113 D111 B013'// B113 -> move+isWide+depth+rotation -> move = B, isWide = 1 (true), depth = 1, rotation = 3 (3 equals to -1)const currentRandomCombination = cubeCombination; // Gets the current key that is in format: 'cubeSize+groupSize+fillRest+fillWithRandom+Combination'// example: '2+1+1+0+B111 L012 B113 D111 B013'// where cubeSize is 2, groupSize is 1, fillRest is true, fillWithRandom is false and Combination is 'B111 L012 B113 D111 B013'const currentKey = cubeKey;
Modifications
// Scrambles the cube cubeSize^3 timescube; // Scrambles the cube 20 times.cube; // Adds cubeSize^3 more generated moves to the combination.cube; // Adds 20 more generated moves to the combination.cube; // Manual string sequence turncube; // Manual object array sequence turncube; // Clears the cube of scramblescube;
Examples
const RubikCipher = ;const cube = 'HelloWorld!' groupSize: 1 fillRest: true fillWithRandom: false;cube; const ciphreKey = cubeKey;const ciphreText = cubeText; const result = ciphreText ciphreKey;const decodedText = resultText;
TypeScript
;;cube.scramble; ;; ;;
Test
npm run test