Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// import visualization libraries {
const { Tracer, Array1DTracer, LogTracer, Layout, VerticalLayout } = require('algorithm-visualizer');
// }
const plainText = 'secret';
// define tracer variables {
const ptTracer = new Array1DTracer('Encryption');
const ctTracer = new Array1DTracer('Decryption');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([ptTracer, ctTracer, logger]));
ptTracer.set(plainText);
Tracer.delay();
// }
/*
code assumes that plainText contains ONLY LOWER CASE ALPHABETS
*/
Number.prototype.mod = function (n) {
return ((this % n) + n) % n;
};
// import visualization libraries {
const { Tracer, Array1DTracer, LogTracer, Layout, VerticalLayout } = require('algorithm-visualizer');
// }
const plainText = 'secret';
// define tracer variables {
const ptTracer = new Array1DTracer('Encryption');
const ctTracer = new Array1DTracer('Decryption');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([ptTracer, ctTracer, logger]));
ptTracer.set(plainText);
Tracer.delay();
// }
/*
code assumes that plainText contains ONLY LOWER CASE ALPHABETS
*/
Number.prototype.mod = function (n) {
return ((this % n) + n) % n;
};
const keys = { a: 5, b: 7 };
// }
// let pattern = "aab";
// let text = "aabxaabxcaabxaabxay";
const pattern = 'abc';
const text = 'xabcabzabc';
const len = pattern.length + text.length + 1;
const z = new Array(len);
z[0] = 0;
// define tracer variables {
const textTracer = new Array1DTracer('text');
const pattTracer = new Array1DTracer('pattern');
const concatTracer = new Array1DTracer('concatenated string');
const tracer = new Array1DTracer('zArray');
pattTracer.set(pattern);
textTracer.set(text);
tracer.set(z);
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([textTracer, pattTracer, concatTracer, tracer, logger]));
Tracer.delay();
// }
function createZarr(concat) {
let left;
let right;
let N;
N = concat.length;
left = 0;
right = 0;
// import visualization libraries {
const { Tracer, Array1DTracer, Array2DTracer, GraphTracer, LogTracer, Randomize, Layout, VerticalLayout } = require('algorithm-visualizer');
// }
function filledArray(length, value) {
return Array(...Array(length)).map(Number.prototype.valueOf, value);
}
// define tracer variables {
const G = Randomize.Graph({ N: 5, ratio: .4 });
let ranks;
const outgoingEdgeCounts = filledArray(G.length, 0);
let incomingNodes;
const graphTracer = new GraphTracer('Web Page inter-connections');
const rankTracer = new Array1DTracer('Web Page Ranks');
const oecTracer = new Array1DTracer('Outgoing Edge Counts');
const inTracer = new Array2DTracer('Incoming Nodes');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([graphTracer, rankTracer, oecTracer, inTracer, logger]));
graphTracer.set(G);
oecTracer.set(outgoingEdgeCounts);
for (incomingNodes = []; incomingNodes.length < G.length; incomingNodes.push(filledArray(G.length, -1))) ;
inTracer.set(incomingNodes);
Tracer.delay();
// }
/*
PageRank Algorithm Version 2
Equation:
import { Array1DTracer, Array2DTracer, GraphTracer, LogTracer, Randomize } from 'algorithm-visualizer';
function filledArray(length, value) {
return Array(...Array(length)).map(Number.prototype.valueOf, value);
}
const G = Randomize.graph(5, { ratio: 0.4 });
let ranks;
const outgoingEdgeCounts = filledArray(G.length, 0);
let incomingNodes;
const graphTracer = new GraphTracer('Web Page inter-connections');
const rankTracer = new Array1DTracer('Web Page Ranks');
const oecTracer = new Array1DTracer('Outgoing Edge Counts');
const inTracer = new Array2DTracer('Incoming Nodes');
const logger = new LogTracer();
graphTracer.set(G);
oecTracer.set(outgoingEdgeCounts);
for (incomingNodes = []; incomingNodes.length < G.length; incomingNodes.push(filledArray(G.length, -1)));
inTracer.set(incomingNodes).delay();
/*
PageRank Algorithm Version 2
Equation:
PR (X) = ( (1 - D)/N ) + D (Summation i->X (PR (I) / Out (i)))
NOTE: Algorithm uses the recommended damping factor (D). Number of iterations is small because only a small Web of 5 Pages is simulated
*/