Merge branch 'artemisbot-feature_vigenere'

This commit is contained in:
n1474335 2016-12-08 00:35:01 +00:00
commit 7994a65926
7 changed files with 148 additions and 24 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -80,6 +80,8 @@ var Categories = [
"ROT47", "ROT47",
"XOR", "XOR",
"XOR Brute Force", "XOR Brute Force",
"Vigenère Encode",
"Vigenère Decode",
"Derive PBKDF2 key", "Derive PBKDF2 key",
"Derive EVP key", "Derive EVP key",
] ]

View File

@ -1325,6 +1325,36 @@ var OperationConfig = {
}, },
] ]
}, },
"Vigenère Encode": {
description: "The Vigenere cipher is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. It is a simple form of polyalphabetic substitution.",
run: Cipher.run_vigenere_enc,
highlight: true,
highlight_reverse: true,
input_type: "string",
output_type: "string",
args: [
{
name: "Key",
type: "string",
value: ""
}
]
},
"Vigenère Decode": {
description: "The Vigenere cipher is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. It is a simple form of polyalphabetic substitution.",
run: Cipher.run_vigenere_dec,
highlight: true,
highlight_reverse: true,
input_type: "string",
output_type: "string",
args: [
{
name: "Key",
type: "string",
value: ""
}
]
},
"Rotate right": { "Rotate right": {
description: "Rotates each byte to the right by the number of bits specified. Currently only supports 8-bit values.", description: "Rotates each byte to the right by the number of bits specified. Currently only supports 8-bit values.",
run: Rotate.run_rotr, run: Rotate.run_rotr,

View File

@ -385,6 +385,96 @@ var Cipher = {
return encrypted.ciphertext.toString(Utils.format[args[2]]); return encrypted.ciphertext.toString(Utils.format[args[2]]);
}, },
/**
* Vigenère Encode operation.
*
* @author Matt C [matt@artemisbot.pw]
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run_vigenere_enc: function (input, args) {
var alphabet = "abcdefghijklmnopqrstuvwxyz",
key = args[0].toLowerCase(),
output = "",
fail = 0,
key_index,
msg_index,
chr;
if (!key) return "No key entered";
if (!/^[a-zA-Z]+$/.test(key)) return "The key must consist only of letters";
for (var i = 0; i < input.length; i++) {
if (alphabet.indexOf(input[i]) >= 0) {
// Get the corresponding character of key for the current letter, accounting
// for chars not in alphabet
chr = key[(i - fail) % key.length];
// Get the location in the vigenere square of the key char
key_index = alphabet.indexOf(chr);
// Get the location in the vigenere square of the message char
msg_index = alphabet.indexOf(input[i]);
// Get the encoded letter by finding the sum of indexes modulo 26 and finding
// the letter corresponding to that
output += alphabet[(key_index + msg_index) % 26];
} else if (alphabet.indexOf(input[i].toLowerCase()) >= 0) {
chr = key[(i - fail) % key.length].toLowerCase();
key_index = alphabet.indexOf(chr);
msg_index = alphabet.indexOf(input[i].toLowerCase());
output += alphabet[(key_index + msg_index) % 26].toUpperCase();
} else {
output += input[i];
fail++;
}
}
return output;
},
/**
* Vigenère Decode operation.
*
* @author Matt C [matt@artemisbot.pw]
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run_vigenere_dec: function (input, args) {
var alphabet = "abcdefghijklmnopqrstuvwxyz",
key = args[0].toLowerCase(),
output = "",
fail = 0,
key_index,
msg_index,
chr;
if (!key) return "No key entered";
if (!/^[a-zA-Z]+$/.test(key)) return "The key must consist only of letters";
for (var i = 0; i < input.length; i++) {
if (alphabet.indexOf(input[i]) >= 0) {
chr = key[(i - fail) % key.length];
key_index = alphabet.indexOf(chr);
msg_index = alphabet.indexOf(input[i]);
// Subtract indexes from each other, add 26 just in case the value is negative,
// modulo to remove if neccessary
output += alphabet[(msg_index - key_index + alphabet.length ) % 26];
} else if (alphabet.indexOf(input[i].toLowerCase()) >= 0) {
chr = key[(i - fail) % key.length].toLowerCase();
key_index = alphabet.indexOf(chr);
msg_index = alphabet.indexOf(input[i].toLowerCase());
output += alphabet[(msg_index + alphabet.length - key_index) % 26].toUpperCase();
} else {
output += input[i];
fail++;
}
}
return output;
},
}; };

View File

@ -1,9 +1,9 @@
202 source files 203 source files
104281 lines 104403 lines
4.0M size 4.0M size
136 JavaScript source files 136 JavaScript source files
95191 lines 95313 lines
3.5M size 3.5M size
78 third party JavaScript source files 78 third party JavaScript source files
@ -11,11 +11,11 @@
2.7M size 2.7M size
58 first party JavaScript source files 58 first party JavaScript source files
18814 lines 18936 lines
728K size 728K size
3.2M uncompressed JavaScript size 3.2M uncompressed JavaScript size
1.7M compressed JavaScript size 1.7M compressed JavaScript size
15 categories 15 categories
153 operations 155 operations