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) {
if (col >= this.size) {
this.printBoard()
this.solutionCount++
return true
}

View File

@ -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 }

View File

@ -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'

View File

@ -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'

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++) {
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

View File

@ -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'

View File

@ -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!'

View File

@ -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'