Implemented lots of blocks
This commit is contained in:
		
							
								
								
									
										41
									
								
								client/src/blocks/affineDecrypt.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								client/src/blocks/affineDecrypt.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Affine Decrypt",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text",
 | 
			
		||||
    a: "a",
 | 
			
		||||
    b: "b"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text, a, b}, elem){
 | 
			
		||||
    a = parseInt(a);
 | 
			
		||||
    b = parseInt(b);
 | 
			
		||||
 | 
			
		||||
    if(isNaN(a)){
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    if(isNaN(b)){
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(!require("./util/coPrime.js")(a, 26)){
 | 
			
		||||
      console.log(a, 26, "not coprime");
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var reverseLookupTable = [];
 | 
			
		||||
    for(var i = 0; i < 26; i++){
 | 
			
		||||
      reverseLookupTable[((a * i) + b)%26] = i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return text
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map(require("./util/toNum.js"))
 | 
			
		||||
    .map((num)=>(reverseLookupTable[num]))
 | 
			
		||||
    .map(require("./util/toChar.js"))
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										41
									
								
								client/src/blocks/affineEncrypt.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								client/src/blocks/affineEncrypt.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Affine Encrypt",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text",
 | 
			
		||||
    a: "a",
 | 
			
		||||
    b: "b"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text, a, b}, elem){
 | 
			
		||||
    a = parseInt(a);
 | 
			
		||||
    b = parseInt(b);
 | 
			
		||||
 | 
			
		||||
    if(isNaN(a)){
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    if(isNaN(b)){
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(!require("./util/coPrime.js")(a, 26)){
 | 
			
		||||
      return "";
 | 
			
		||||
      console.log(a, 26, "not coprime");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var lookupTable = [];
 | 
			
		||||
    for(var i = 0; i < 26; i++){
 | 
			
		||||
      lookupTable[i] = ((a * i) + b)%26;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return text
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map(require("./util/toNum.js"))
 | 
			
		||||
    .map((num)=>(lookupTable[num]))
 | 
			
		||||
    .map(require("./util/toChar.js"))
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								client/src/blocks/asciiToHex.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								client/src/blocks/asciiToHex.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "ASCII to Hex",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text}, elem){
 | 
			
		||||
    return text
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map((char)=>(char.charCodeAt(0)))
 | 
			
		||||
    .map((int)=>(int.toString(16)))
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								client/src/blocks/atbash.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								client/src/blocks/atbash.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Atbash",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text}, elem){
 | 
			
		||||
    return text
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map(require("./util/toNum.js"))
 | 
			
		||||
    .map((num)=>{
 | 
			
		||||
      if(Number.isInteger(num)){
 | 
			
		||||
        return 25 - num;
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        return num;
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    .map(require("./util/toChar.js"))
 | 
			
		||||
    .join("")
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								client/src/blocks/caesar.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								client/src/blocks/caesar.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Caesar",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text",
 | 
			
		||||
    shift: "Shift"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text, shift}, elem){
 | 
			
		||||
    if(!isNaN(parseInt(shift))){
 | 
			
		||||
      shift = parseInt(shift);
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      shift = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return text
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map(require("./util/toNum.js"))
 | 
			
		||||
    .map((num)=>{
 | 
			
		||||
      if(Number.isInteger(num)){
 | 
			
		||||
        return ((num + shift)%26 + 26)%26;
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        return num;
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    .map(require("./util/toChar.js"))
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								client/src/blocks/elementsToNumbers.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								client/src/blocks/elementsToNumbers.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Elements to Numbers",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    elements: "Elements"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({elements}, elem){
 | 
			
		||||
    return elements
 | 
			
		||||
    .split(",")
 | 
			
		||||
    .map((element)=>(require("./util/elements.js").indexOf(element.toLowerCase()) + 1))
 | 
			
		||||
    .filter((num)=>(num > 0))
 | 
			
		||||
    .join(",");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								client/src/blocks/hexToAscii.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								client/src/blocks/hexToAscii.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Hex to ASCII",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    hex: "Hex String"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({hex}, elem){
 | 
			
		||||
    return hex
 | 
			
		||||
    .split("")
 | 
			
		||||
    .filter((digit)=>(!isNaN(parseInt(digit, 16))))
 | 
			
		||||
    .reduce((pairs, digit)=>{
 | 
			
		||||
      if(pairs[pairs.length - 1].length < 2){
 | 
			
		||||
        pairs[pairs.length - 1] += digit
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        pairs.push([digit]);
 | 
			
		||||
      }
 | 
			
		||||
      return pairs;
 | 
			
		||||
    }, [""])
 | 
			
		||||
    .filter((pair)=>(pair.length == 2))
 | 
			
		||||
    .map((pair)=>(parseInt(pair, 16)))
 | 
			
		||||
    .map((int)=>(String.fromCharCode(int)))
 | 
			
		||||
    .join("")
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,25 @@
 | 
			
		||||
module.exports = {
 | 
			
		||||
  input: require("./input.js"),
 | 
			
		||||
  output: require("./output.js"),
 | 
			
		||||
  concat: require("./concat.js")
 | 
			
		||||
}
 | 
			
		||||
var blocks = [
 | 
			
		||||
  "input",
 | 
			
		||||
  "output",
 | 
			
		||||
  "reverse",
 | 
			
		||||
  "numsToLetters",
 | 
			
		||||
  "lettersToNums",
 | 
			
		||||
  "hexToAscii",
 | 
			
		||||
  "asciiToHex",
 | 
			
		||||
  "vigenereEncode",
 | 
			
		||||
  "vigenereDecode",
 | 
			
		||||
  "caesar",
 | 
			
		||||
  "affineEncrypt",
 | 
			
		||||
  "affineDecrypt",
 | 
			
		||||
  "atbash",
 | 
			
		||||
  "numbersToElements",
 | 
			
		||||
  "elementsToNumbers",
 | 
			
		||||
  "transposition",
 | 
			
		||||
  "transpositionReverse",
 | 
			
		||||
  "substitution",
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
module.exports = blocks.reduce((blocks, block)=>{
 | 
			
		||||
  blocks[block] = require("./" + block + ".js");
 | 
			
		||||
  return blocks;
 | 
			
		||||
}, {});
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										35
									
								
								client/src/blocks/lettersToNums.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								client/src/blocks/lettersToNums.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Letters to Numbers",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    letters: "Letters",
 | 
			
		||||
    offset: "Offset"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({letters, offset}, elem){
 | 
			
		||||
    if(!offset){
 | 
			
		||||
      offset = 0;
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      offset = parseInt(offset);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return letters
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map((char)=>(char.charCodeAt(0)))
 | 
			
		||||
    .filter((asciiVal)=>(((asciiVal >= 65) && (asciiVal <= 90)) || ((asciiVal >= 97) && (asciiVal <= 122))))
 | 
			
		||||
    .map((asciiVal)=>{
 | 
			
		||||
      if(asciiVal <= 90){
 | 
			
		||||
        return asciiVal - 65;
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        return asciiVal - 97;
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    .map((num)=>(num + offset))
 | 
			
		||||
    .join(",");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								client/src/blocks/numbersToElements.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								client/src/blocks/numbersToElements.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Numbers to Elements",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    numbers: "Numbers"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({numbers}, elem){
 | 
			
		||||
    return numbers
 | 
			
		||||
    .split(",")
 | 
			
		||||
    .map((num)=>(parseInt(num)))
 | 
			
		||||
    .filter((num)=>(!isNaN(num)))
 | 
			
		||||
    .map((num)=>(require("./util/elements.js")[num-1]))
 | 
			
		||||
    .join(",");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										47
									
								
								client/src/blocks/numsToLetters.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								client/src/blocks/numsToLetters.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Numbers to Letters",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    nums: "Numbers",
 | 
			
		||||
    offset: "Offset"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({nums, offset}, elem){
 | 
			
		||||
    if(!offset){
 | 
			
		||||
      offset = 0;
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
      offset = parseInt(offset);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return nums
 | 
			
		||||
    .split(",")
 | 
			
		||||
    .filter((num)=>(num))
 | 
			
		||||
    .map((num)=>(parseInt(num)))
 | 
			
		||||
    .filter((num)=>(!isNaN(num)))
 | 
			
		||||
    .map((num)=>(num - offset))
 | 
			
		||||
    .map((num)=>(num%52))
 | 
			
		||||
    .map((num)=>{
 | 
			
		||||
      if(num < 0){
 | 
			
		||||
        return 52 + num;
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        return num;
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    .map((num)=>{
 | 
			
		||||
      if(num < 26){
 | 
			
		||||
        asciiOffset = 97;
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        asciiOffset = 65 - 26;
 | 
			
		||||
      }
 | 
			
		||||
      return num + asciiOffset;
 | 
			
		||||
    })
 | 
			
		||||
    .map((asciiVal)=>(String.fromCharCode(asciiVal)))
 | 
			
		||||
    .join("")
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								client/src/blocks/reverse.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								client/src/blocks/reverse.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Reverse",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    input: "Input"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({input}, elem){
 | 
			
		||||
    return input
 | 
			
		||||
    .split("")
 | 
			
		||||
    .reverse()
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								client/src/blocks/substitution.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								client/src/blocks/substitution.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Substitution",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text",
 | 
			
		||||
    mapping: "Mapping"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text, mapping}, elem){
 | 
			
		||||
    mapping = mapping.toLowerCase();
 | 
			
		||||
    var letterMapping = {};
 | 
			
		||||
    for(var i = 0; i < (mapping.length - 1); i++){
 | 
			
		||||
      letterMapping[mapping[i]] = mapping[i+1];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return text
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map((char)=>{
 | 
			
		||||
      if(char.toLowerCase() in letterMapping){
 | 
			
		||||
        if(char.toLowerCase() == char){
 | 
			
		||||
          return letterMapping[char];
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
          return letterMapping[char.toLowerCase()].toUpperCase();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        return char;
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,16 +1,14 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Example Block",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    input1: "Input 1",
 | 
			
		||||
    input2: "Input 2"
 | 
			
		||||
    input: "Input"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({input1}, elem){
 | 
			
		||||
    $(elem).find("div.input1").html(input1);
 | 
			
		||||
    return (output = parseInt(input1) + 1).toString();
 | 
			
		||||
  execute: function({input}, elem){
 | 
			
		||||
    return input;
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "<div class='input1'></div>",
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								client/src/blocks/transposition.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								client/src/blocks/transposition.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Transposition",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text",
 | 
			
		||||
    n: "n"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text, n}, elem){
 | 
			
		||||
    var n = parseInt(n);
 | 
			
		||||
 | 
			
		||||
    text = text.replace(/[ ,.]/g, "");
 | 
			
		||||
 | 
			
		||||
    var output = "";
 | 
			
		||||
    x = 0;
 | 
			
		||||
    for(var i = 0; i < n; i++){
 | 
			
		||||
      for(var y = i; y < text.length; y += n){
 | 
			
		||||
        output += text[y];
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return output;
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								client/src/blocks/transpositionReverse.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								client/src/blocks/transpositionReverse.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Transposition Reverse",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    text: "Text",
 | 
			
		||||
    n: "n"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({text, n}, elem){
 | 
			
		||||
    var n = parseInt(n);
 | 
			
		||||
 | 
			
		||||
    text = text.replace(/[ ,.]/g, "");
 | 
			
		||||
 | 
			
		||||
    var output = [];
 | 
			
		||||
    x = 0;
 | 
			
		||||
    var z = 0;
 | 
			
		||||
    for(var i = 0; i < n; i++){
 | 
			
		||||
      for(var y = i; y < text.length; y += n){
 | 
			
		||||
        output[y] = text[z];
 | 
			
		||||
        z++;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return output.join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								client/src/blocks/util/coPrime.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								client/src/blocks/util/coPrime.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
function getFactors(num){
 | 
			
		||||
  factors = [];
 | 
			
		||||
  for(var i = 2; i <= num; i++){
 | 
			
		||||
    if(num%i == 0){
 | 
			
		||||
      factors.push(i);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return factors;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function coPrime(a, b){
 | 
			
		||||
  aFactors = getFactors(a);
 | 
			
		||||
  bFactors = getFactors(b);
 | 
			
		||||
  common = aFactors.filter((factor)=>(bFactors.indexOf(factor) > -1));
 | 
			
		||||
 | 
			
		||||
  return (common.length == 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = coPrime;
 | 
			
		||||
							
								
								
									
										120
									
								
								client/src/blocks/util/elements.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								client/src/blocks/util/elements.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,120 @@
 | 
			
		||||
module.exports =[
 | 
			
		||||
  "h",
 | 
			
		||||
  "he",
 | 
			
		||||
  "li",
 | 
			
		||||
  "be",
 | 
			
		||||
  "b",
 | 
			
		||||
  "c",
 | 
			
		||||
  "n",
 | 
			
		||||
  "o",
 | 
			
		||||
  "f",
 | 
			
		||||
  "ne",
 | 
			
		||||
  "na",
 | 
			
		||||
  "mg",
 | 
			
		||||
  "al",
 | 
			
		||||
  "si",
 | 
			
		||||
  "p",
 | 
			
		||||
  "s",
 | 
			
		||||
  "cl",
 | 
			
		||||
  "ar",
 | 
			
		||||
  "k",
 | 
			
		||||
  "ca",
 | 
			
		||||
  "sc",
 | 
			
		||||
  "ti",
 | 
			
		||||
  "v",
 | 
			
		||||
  "cr",
 | 
			
		||||
  "mn",
 | 
			
		||||
  "fe",
 | 
			
		||||
  "co",
 | 
			
		||||
  "ni",
 | 
			
		||||
  "cu",
 | 
			
		||||
  "zn",
 | 
			
		||||
  "ga",
 | 
			
		||||
  "ge",
 | 
			
		||||
  "as",
 | 
			
		||||
  "se",
 | 
			
		||||
  "br",
 | 
			
		||||
  "kr",
 | 
			
		||||
  "rb",
 | 
			
		||||
  "sr",
 | 
			
		||||
  "y",
 | 
			
		||||
  "zr",
 | 
			
		||||
  "nb",
 | 
			
		||||
  "mo",
 | 
			
		||||
  "tc",
 | 
			
		||||
  "ru",
 | 
			
		||||
  "rh",
 | 
			
		||||
  "pd",
 | 
			
		||||
  "ag",
 | 
			
		||||
  "cd",
 | 
			
		||||
  "in",
 | 
			
		||||
  "sn",
 | 
			
		||||
  "sb",
 | 
			
		||||
  "te",
 | 
			
		||||
  "i",
 | 
			
		||||
  "xe",
 | 
			
		||||
  "cs",
 | 
			
		||||
  "ba",
 | 
			
		||||
  "la",
 | 
			
		||||
  "ce",
 | 
			
		||||
  "pr",
 | 
			
		||||
  "nd",
 | 
			
		||||
  "pm",
 | 
			
		||||
  "sm",
 | 
			
		||||
  "eu",
 | 
			
		||||
  "gd",
 | 
			
		||||
  "tb",
 | 
			
		||||
  "dy",
 | 
			
		||||
  "ho",
 | 
			
		||||
  "er",
 | 
			
		||||
  "tm",
 | 
			
		||||
  "yb",
 | 
			
		||||
  "lu",
 | 
			
		||||
  "hf",
 | 
			
		||||
  "ta",
 | 
			
		||||
  "w",
 | 
			
		||||
  "re",
 | 
			
		||||
  "os",
 | 
			
		||||
  "ir",
 | 
			
		||||
  "pt",
 | 
			
		||||
  "au",
 | 
			
		||||
  "hg",
 | 
			
		||||
  "tl",
 | 
			
		||||
  "pb",
 | 
			
		||||
  "bi",
 | 
			
		||||
  "po",
 | 
			
		||||
  "at",
 | 
			
		||||
  "rn",
 | 
			
		||||
  "fr",
 | 
			
		||||
  "ra",
 | 
			
		||||
  "ac",
 | 
			
		||||
  "th",
 | 
			
		||||
  "pa",
 | 
			
		||||
  "u",
 | 
			
		||||
  "np",
 | 
			
		||||
  "pu",
 | 
			
		||||
  "am",
 | 
			
		||||
  "cm",
 | 
			
		||||
  "bk",
 | 
			
		||||
  "cf",
 | 
			
		||||
  "es",
 | 
			
		||||
  "fm",
 | 
			
		||||
  "md",
 | 
			
		||||
  "no",
 | 
			
		||||
  "lr",
 | 
			
		||||
  "rf",
 | 
			
		||||
  "db",
 | 
			
		||||
  "sg",
 | 
			
		||||
  "bh",
 | 
			
		||||
  "hs",
 | 
			
		||||
  "mt",
 | 
			
		||||
  "ds",
 | 
			
		||||
  "rg",
 | 
			
		||||
  "cn",
 | 
			
		||||
  "nh",
 | 
			
		||||
  "fl",
 | 
			
		||||
  "mc",
 | 
			
		||||
  "lv",
 | 
			
		||||
  "ts",
 | 
			
		||||
  "og"
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										8
									
								
								client/src/blocks/util/toChar.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								client/src/blocks/util/toChar.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
module.exports = function(num){
 | 
			
		||||
  if(Number.isInteger(num)){
 | 
			
		||||
    return String.fromCharCode(num + 97);
 | 
			
		||||
  }
 | 
			
		||||
  else{
 | 
			
		||||
    return num;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								client/src/blocks/util/toNum.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								client/src/blocks/util/toNum.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
module.exports = function(char){
 | 
			
		||||
  var num = char.toLowerCase().charCodeAt(0) - 97;
 | 
			
		||||
  if((num >= 0) && (num < 26)){
 | 
			
		||||
    return num;
 | 
			
		||||
  }
 | 
			
		||||
  else{
 | 
			
		||||
    return char;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								client/src/blocks/vigenereDecode.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								client/src/blocks/vigenereDecode.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Vigenere Decode",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    cipherText: "Ciphertext",
 | 
			
		||||
    key: "key"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({cipherText, key}, elem){
 | 
			
		||||
    var keyNums = key.split("").map(require("./util/toNum.js"));
 | 
			
		||||
 | 
			
		||||
    return cipherText
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map(require("./util/toNum.js"))
 | 
			
		||||
    .map((int, pos, ints)=>{
 | 
			
		||||
      if(Number.isInteger(int)){
 | 
			
		||||
        var realCharsPosition = ints.slice(0, pos).filter((num)=>(Number.isInteger(num))).length;
 | 
			
		||||
        return (int + 26 - keyNums[realCharsPosition%key.length])%26;
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        return int;
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    .map(require("./util/toChar.js"))
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								client/src/blocks/vigenereEncode.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								client/src/blocks/vigenereEncode.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
module.exports =  {
 | 
			
		||||
  name: "Vigenere Encode",
 | 
			
		||||
  inputs: {
 | 
			
		||||
    plaintext: "Plaintext",
 | 
			
		||||
    key: "Key"
 | 
			
		||||
  },
 | 
			
		||||
  output: true,
 | 
			
		||||
  execute: function({plaintext, key}, elem){
 | 
			
		||||
    var keyNums = key.split("").map(require("./util/toNum.js"));
 | 
			
		||||
 | 
			
		||||
    return plaintext
 | 
			
		||||
    .split("")
 | 
			
		||||
    .map(require("./util/toNum.js"))
 | 
			
		||||
    .map((int, pos, ints)=>{
 | 
			
		||||
      if(Number.isInteger(int)){
 | 
			
		||||
        var realCharsPosition = ints.slice(0, pos).filter((num)=>(Number.isInteger(num))).length;
 | 
			
		||||
        return (int + keyNums[realCharsPosition % key.length]) % 26;
 | 
			
		||||
      }
 | 
			
		||||
      else{
 | 
			
		||||
        return int;
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    .map(require("./util/toChar.js"))
 | 
			
		||||
    .join("");
 | 
			
		||||
  },
 | 
			
		||||
  pageBlock: {
 | 
			
		||||
    html: "",
 | 
			
		||||
    js: function(){}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -12,6 +12,7 @@ body{
 | 
			
		||||
#blocks{
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: row;
 | 
			
		||||
  overflow-x: scroll;
 | 
			
		||||
  .block{
 | 
			
		||||
    margin: 10px;
 | 
			
		||||
  }
 | 
			
		||||
@@ -23,6 +24,7 @@ body{
 | 
			
		||||
  border: 1px solid black;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
  flex-shrink: 0;
 | 
			
		||||
  background-color: white;
 | 
			
		||||
  .inputs{
 | 
			
		||||
    display: flex;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user