diff --git a/Backtracking/NQueen.js b/Backtracking/NQueen.js index d76f232125..4b830dc73b 100644 --- a/Backtracking/NQueen.js +++ b/Backtracking/NQueen.js @@ -36,7 +36,6 @@ class NQueen { solve (col = 0) { if (col >= this.size) { - this.printBoard() this.solutionCount++ return true } diff --git a/Bit-Manipulation/BinaryCountSetBits.js b/Bit-Manipulation/BinaryCountSetBits.js index 3fcb9d619c..60ae791231 100644 --- a/Bit-Manipulation/BinaryCountSetBits.js +++ b/Bit-Manipulation/BinaryCountSetBits.js @@ -13,5 +13,4 @@ function BinaryCountSetBits (a) { return a.toString(2).split('1').length - 1 } -// Run `binary_and` Function to find the binary and operation -console.log(BinaryCountSetBits(251)) +export { BinaryCountSetBits } diff --git a/Ciphers/Atbash.js b/Ciphers/Atbash.js index 5f43737497..8ab7105fe2 100644 --- a/Ciphers/Atbash.js +++ b/Ciphers/Atbash.js @@ -23,7 +23,8 @@ function Atbash (message) { } return decodedString } -// Atbash Example -const encryptedString = 'HELLO WORLD' -const decryptedString = Atbash(encryptedString) -console.log(decryptedString) // SVOOL DLIOW + +export { Atbash } + +// > Atbash('HELLO WORLD') +// 'SVOOL DLIOW' diff --git a/Ciphers/CaesarsCipher.js b/Ciphers/CaesarsCipher.js index 00bf1f1c1b..20e40c1ec4 100644 --- a/Ciphers/CaesarsCipher.js +++ b/Ciphers/CaesarsCipher.js @@ -29,8 +29,7 @@ function rot13 (str) { return response.join('') } -// Caesars Cipher Example -const encryptedString = 'Uryyb Jbeyq' -const decryptedString = rot13(encryptedString) +export { rot13 } -console.log(decryptedString) // Hello World +// > rot13('Uryyb Jbeyq') +// 'Hello World' diff --git a/Ciphers/KeyFinder.js b/Ciphers/KeyFinder.js index 1a4059e335..add581f65b 100644 --- a/Ciphers/KeyFinder.js +++ b/Ciphers/KeyFinder.js @@ -44,15 +44,11 @@ function keyFinder (str) { // str is used to get the input of encrypted string for (let w = 0; w < wordBank[i].length; w++) { outStrElement += outStr[s + w] } - - // console.log( k + outStrElement + wordBank[i] );//debug - // this part need to be optimize with the calculation of the number of occurrence of word's probabilities // linked list will be used in the next stage of development to calculate the number of occurrence of the key if (wordBank[i] === outStrElement) { return k // return the key number if founded } - outStrElement = '' // reset the temp word } // end for ( let i=0; i < wordBank.length; i++) } @@ -145,4 +141,7 @@ function caesarCipherEncodeAndDecodeEngine (inStr, numShifted) { return outStr } -console.log('Testing: ' + keyFinder('test')) // returns 0 +export { keyFinder } + +// > keyFinder('test') +// 0 diff --git a/Ciphers/ROT13.js b/Ciphers/ROT13.js index 24eeacf8e1..e644b20283 100644 --- a/Ciphers/ROT13.js +++ b/Ciphers/ROT13.js @@ -3,7 +3,7 @@ * @param {String} text - string to be encrypted * @return {String} - decrypted string */ -const transcipher = (text) => { +const ROT13 = (text) => { const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm' const index = x => originalCharacterList.indexOf(x) @@ -11,11 +11,7 @@ const transcipher = (text) => { return text.split('').map(replace).join('') } -(() => { - const messageToBeEncrypted = 'The quick brown fox jumps over the lazy dog' - console.log(`Original Text = "${messageToBeEncrypted}"`) - const rot13CipheredText = transcipher(messageToBeEncrypted) - console.log(`Ciphered Text = "${rot13CipheredText}"`) - const rot13DecipheredText = transcipher(rot13CipheredText) - console.log(`Deciphered Text = "${rot13DecipheredText}"`) -})() +export { ROT13 } + +// > ROT13('The quick brown fox jumps over the lazy dog') +// 'Gur dhvpx oebja sbk whzcf bire gur ynml qbt' diff --git a/Ciphers/VigenereCipher.js b/Ciphers/VigenereCipher.js index 68ef3e85a0..800c3fdd94 100644 --- a/Ciphers/VigenereCipher.js +++ b/Ciphers/VigenereCipher.js @@ -71,8 +71,11 @@ function decrypt (message, key) { return result } -const messageEncrypt = encrypt('Hello World!', 'code') -console.log(messageEncrypt) // "Jhpnr Yrvng!" +export { encrypt, decrypt } -const messageDecrypt = decrypt('Jsopq Zstzg!', 'code') -console.log(messageDecrypt) // "Hello World!" + +// > encrypt('Hello World!', 'code') +// 'Jsopq Zstzg!' + +// > decrypt('Jsopq Zstzg!', 'code') +// 'Hello World!' diff --git a/Ciphers/XORCipher.js b/Ciphers/XORCipher.js index 898b200dd6..2ee8205fbf 100644 --- a/Ciphers/XORCipher.js +++ b/Ciphers/XORCipher.js @@ -20,7 +20,13 @@ function XOR (str, key) { return result } -const encryptedString = XOR('test string', 32) -console.log('Encrypted: ', encryptedString) -const decryptedString = XOR(encryptedString, 32) -console.log('Decrypted: ', decryptedString) +export { XOR } + + +// Nb: Node REPL might not output the null char '\x00' (charcode 0) + +// > XOR('test string', 32) +// 'TEST\x00STRING' + +// > XOR('TEST\x00STRING', 32) +// 'test string'