Remove live code & console.log (Backtracking, Bit-manipulation, Ciphers).

This commit is contained in:
Eric Lavault
2021-10-09 17:47:03 +02:00
parent 7f6a53ad4a
commit 5c4be7604d
8 changed files with 35 additions and 33 deletions

View File

@ -36,7 +36,6 @@ class NQueen {
solve (col = 0) { solve (col = 0) {
if (col >= this.size) { if (col >= this.size) {
this.printBoard()
this.solutionCount++ this.solutionCount++
return true return true
} }

View File

@ -13,5 +13,4 @@ function BinaryCountSetBits (a) {
return a.toString(2).split('1').length - 1 return a.toString(2).split('1').length - 1
} }
// Run `binary_and` Function to find the binary and operation export { BinaryCountSetBits }
console.log(BinaryCountSetBits(251))

View File

@ -23,7 +23,8 @@ function Atbash (message) {
} }
return decodedString return decodedString
} }
// Atbash Example
const encryptedString = 'HELLO WORLD' export { Atbash }
const decryptedString = Atbash(encryptedString)
console.log(decryptedString) // SVOOL DLIOW // > Atbash('HELLO WORLD')
// 'SVOOL DLIOW'

View File

@ -29,8 +29,7 @@ function rot13 (str) {
return response.join('') return response.join('')
} }
// Caesars Cipher Example export { rot13 }
const encryptedString = 'Uryyb Jbeyq'
const decryptedString = rot13(encryptedString)
console.log(decryptedString) // Hello World // > rot13('Uryyb Jbeyq')
// 'Hello World'

View File

@ -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++) { for (let w = 0; w < wordBank[i].length; w++) {
outStrElement += outStr[s + 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 // 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 // linked list will be used in the next stage of development to calculate the number of occurrence of the key
if (wordBank[i] === outStrElement) { if (wordBank[i] === outStrElement) {
return k // return the key number if founded return k // return the key number if founded
} }
outStrElement = '' // reset the temp word outStrElement = '' // reset the temp word
} // end for ( let i=0; i < wordBank.length; i++) } // end for ( let i=0; i < wordBank.length; i++)
} }
@ -145,4 +141,7 @@ function caesarCipherEncodeAndDecodeEngine (inStr, numShifted) {
return outStr return outStr
} }
console.log('Testing: ' + keyFinder('test')) // returns 0 export { keyFinder }
// > keyFinder('test')
// 0

View File

@ -3,7 +3,7 @@
* @param {String} text - string to be encrypted * @param {String} text - string to be encrypted
* @return {String} - decrypted string * @return {String} - decrypted string
*/ */
const transcipher = (text) => { const ROT13 = (text) => {
const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm' const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
const index = x => originalCharacterList.indexOf(x) const index = x => originalCharacterList.indexOf(x)
@ -11,11 +11,7 @@ const transcipher = (text) => {
return text.split('').map(replace).join('') return text.split('').map(replace).join('')
} }
(() => { export { ROT13 }
const messageToBeEncrypted = 'The quick brown fox jumps over the lazy dog'
console.log(`Original Text = "${messageToBeEncrypted}"`) // > ROT13('The quick brown fox jumps over the lazy dog')
const rot13CipheredText = transcipher(messageToBeEncrypted) // 'Gur dhvpx oebja sbk whzcf bire gur ynml qbt'
console.log(`Ciphered Text = "${rot13CipheredText}"`)
const rot13DecipheredText = transcipher(rot13CipheredText)
console.log(`Deciphered Text = "${rot13DecipheredText}"`)
})()

View File

@ -71,8 +71,11 @@ function decrypt (message, key) {
return result return result
} }
const messageEncrypt = encrypt('Hello World!', 'code') export { encrypt, decrypt }
console.log(messageEncrypt) // "Jhpnr Yrvng!"
const messageDecrypt = decrypt('Jsopq Zstzg!', 'code')
console.log(messageDecrypt) // "Hello World!" // > encrypt('Hello World!', 'code')
// 'Jsopq Zstzg!'
// > decrypt('Jsopq Zstzg!', 'code')
// 'Hello World!'

View File

@ -20,7 +20,13 @@ function XOR (str, key) {
return result return result
} }
const encryptedString = XOR('test string', 32) export { XOR }
console.log('Encrypted: ', encryptedString)
const decryptedString = XOR(encryptedString, 32)
console.log('Decrypted: ', decryptedString) // Nb: Node REPL might not output the null char '\x00' (charcode 0)
// > XOR('test string', 32)
// 'TEST\x00STRING'
// > XOR('TEST\x00STRING', 32)
// 'test string'