Skip to content

Commit

Permalink
Remove live code & console.log (Backtracking, Bit-manipulation, Ciphe…
Browse files Browse the repository at this point in the history
…rs).
  • Loading branch information
lvlte committed Oct 9, 2021
1 parent 7f6a53a commit 5c4be76
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
1 change: 0 additions & 1 deletion Backtracking/NQueen.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class NQueen {

solve (col = 0) {
if (col >= this.size) {
this.printBoard()
this.solutionCount++
return true
}
Expand Down
3 changes: 1 addition & 2 deletions Bit-Manipulation/BinaryCountSetBits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
9 changes: 5 additions & 4 deletions Ciphers/Atbash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 3 additions & 4 deletions Ciphers/CaesarsCipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 4 additions & 5 deletions Ciphers/KeyFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
}
Expand Down Expand Up @@ -145,4 +141,7 @@ function caesarCipherEncodeAndDecodeEngine (inStr, numShifted) {
return outStr
}

console.log('Testing: ' + keyFinder('test')) // returns 0
export { keyFinder }

// > keyFinder('test')
// 0
14 changes: 5 additions & 9 deletions Ciphers/ROT13.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
* @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)
const replace = x => index(x) > -1 ? toBeMappedCharaterList[index(x)] : x
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'
11 changes: 7 additions & 4 deletions Ciphers/VigenereCipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
14 changes: 10 additions & 4 deletions Ciphers/XORCipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 5c4be76

Please sign in to comment.