mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Built production version with Base58 and NetBIOS operations. Closes #48.
This commit is contained in:
parent
701ea5890d
commit
92bd2c921e
8 changed files with 51 additions and 53 deletions
|
@ -9,7 +9,6 @@
|
|||
*/
|
||||
var Base58 = {
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
|
@ -24,15 +23,12 @@ var Base58 = {
|
|||
value: "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",
|
||||
},
|
||||
],
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
REMOVE_NON_ALPH_CHARS: true,
|
||||
|
||||
|
||||
/**
|
||||
* To Base58 operation.
|
||||
*
|
||||
|
@ -41,7 +37,10 @@ var Base58 = {
|
|||
* @returns {string}
|
||||
*/
|
||||
runTo: function(input, args) {
|
||||
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value;
|
||||
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value,
|
||||
result = [0];
|
||||
|
||||
alphabet = Utils.expandAlphRange(alphabet).join("");
|
||||
|
||||
if (alphabet.length !== 58 ||
|
||||
[].unique.call(alphabet).length !== 58) {
|
||||
|
@ -50,8 +49,6 @@ var Base58 = {
|
|||
|
||||
if (input.length === 0) return "";
|
||||
|
||||
var result = [0];
|
||||
|
||||
input.forEach(function(b) {
|
||||
var carry = (result[0] << 8) + b;
|
||||
result[0] = carry % 58;
|
||||
|
@ -89,21 +86,19 @@ var Base58 = {
|
|||
* @returns {byteArray}
|
||||
*/
|
||||
runFrom: function(input, args) {
|
||||
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value;
|
||||
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value,
|
||||
removeNonAlphaChars = args[1] === undefined ? true : args[1],
|
||||
result = [0];
|
||||
|
||||
alphabet = Utils.expandAlphRange(alphabet).join("");
|
||||
|
||||
if (alphabet.length !== 58 ||
|
||||
[].unique.call(alphabet).length !== 58) {
|
||||
throw ("Alphabet must be of length 58");
|
||||
}
|
||||
|
||||
var removeNonAlphaChars = args[1];
|
||||
if (removeNonAlphaChars === undefined)
|
||||
removeNonAlphaChars = true;
|
||||
|
||||
if (input.length === 0) return [];
|
||||
|
||||
var result = [0];
|
||||
|
||||
[].forEach.call(input, function(c, charIndex) {
|
||||
var index = alphabet.indexOf(c);
|
||||
|
||||
|
@ -111,7 +106,7 @@ var Base58 = {
|
|||
if (removeNonAlphaChars) {
|
||||
return;
|
||||
} else {
|
||||
throw ("Char " + c + " not in alphabet");
|
||||
throw ("Char '" + c + "' at position " + charIndex + " not in alphabet");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,4 +128,5 @@ var Base58 = {
|
|||
|
||||
return result.reverse();
|
||||
},
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue