Skip to content

Commit 5c4be76

Browse files
committed
Remove live code & console.log (Backtracking, Bit-manipulation, Ciphers).
1 parent 7f6a53a commit 5c4be76

File tree

8 files changed

+35
-33
lines changed

8 files changed

+35
-33
lines changed

Backtracking/NQueen.js

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class NQueen {
3636

3737
solve (col = 0) {
3838
if (col >= this.size) {
39-
this.printBoard()
4039
this.solutionCount++
4140
return true
4241
}

Bit-Manipulation/BinaryCountSetBits.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ function BinaryCountSetBits (a) {
1313
return a.toString(2).split('1').length - 1
1414
}
1515

16-
// Run `binary_and` Function to find the binary and operation
17-
console.log(BinaryCountSetBits(251))
16+
export { BinaryCountSetBits }

Ciphers/Atbash.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function Atbash (message) {
2323
}
2424
return decodedString
2525
}
26-
// Atbash Example
27-
const encryptedString = 'HELLO WORLD'
28-
const decryptedString = Atbash(encryptedString)
29-
console.log(decryptedString) // SVOOL DLIOW
26+
27+
export { Atbash }
28+
29+
// > Atbash('HELLO WORLD')
30+
// 'SVOOL DLIOW'

Ciphers/CaesarsCipher.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ function rot13 (str) {
2929
return response.join('')
3030
}
3131

32-
// Caesars Cipher Example
33-
const encryptedString = 'Uryyb Jbeyq'
34-
const decryptedString = rot13(encryptedString)
32+
export { rot13 }
3533

36-
console.log(decryptedString) // Hello World
34+
// > rot13('Uryyb Jbeyq')
35+
// 'Hello World'

Ciphers/KeyFinder.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,11 @@ function keyFinder (str) { // str is used to get the input of encrypted string
4444
for (let w = 0; w < wordBank[i].length; w++) {
4545
outStrElement += outStr[s + w]
4646
}
47-
48-
// console.log( k + outStrElement + wordBank[i] );//debug
49-
5047
// this part need to be optimize with the calculation of the number of occurrence of word's probabilities
5148
// linked list will be used in the next stage of development to calculate the number of occurrence of the key
5249
if (wordBank[i] === outStrElement) {
5350
return k // return the key number if founded
5451
}
55-
5652
outStrElement = '' // reset the temp word
5753
} // end for ( let i=0; i < wordBank.length; i++)
5854
}
@@ -145,4 +141,7 @@ function caesarCipherEncodeAndDecodeEngine (inStr, numShifted) {
145141
return outStr
146142
}
147143

148-
console.log('Testing: ' + keyFinder('test')) // returns 0
144+
export { keyFinder }
145+
146+
// > keyFinder('test')
147+
// 0

Ciphers/ROT13.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
* @param {String} text - string to be encrypted
44
* @return {String} - decrypted string
55
*/
6-
const transcipher = (text) => {
6+
const ROT13 = (text) => {
77
const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
88
const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
99
const index = x => originalCharacterList.indexOf(x)
1010
const replace = x => index(x) > -1 ? toBeMappedCharaterList[index(x)] : x
1111
return text.split('').map(replace).join('')
1212
}
1313

14-
(() => {
15-
const messageToBeEncrypted = 'The quick brown fox jumps over the lazy dog'
16-
console.log(`Original Text = "${messageToBeEncrypted}"`)
17-
const rot13CipheredText = transcipher(messageToBeEncrypted)
18-
console.log(`Ciphered Text = "${rot13CipheredText}"`)
19-
const rot13DecipheredText = transcipher(rot13CipheredText)
20-
console.log(`Deciphered Text = "${rot13DecipheredText}"`)
21-
})()
14+
export { ROT13 }
15+
16+
// > ROT13('The quick brown fox jumps over the lazy dog')
17+
// 'Gur dhvpx oebja sbk whzcf bire gur ynml qbt'

Ciphers/VigenereCipher.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ function decrypt (message, key) {
7171
return result
7272
}
7373

74-
const messageEncrypt = encrypt('Hello World!', 'code')
75-
console.log(messageEncrypt) // "Jhpnr Yrvng!"
74+
export { encrypt, decrypt }
7675

77-
const messageDecrypt = decrypt('Jsopq Zstzg!', 'code')
78-
console.log(messageDecrypt) // "Hello World!"
76+
77+
// > encrypt('Hello World!', 'code')
78+
// 'Jsopq Zstzg!'
79+
80+
// > decrypt('Jsopq Zstzg!', 'code')
81+
// 'Hello World!'

Ciphers/XORCipher.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ function XOR (str, key) {
2020
return result
2121
}
2222

23-
const encryptedString = XOR('test string', 32)
24-
console.log('Encrypted: ', encryptedString)
25-
const decryptedString = XOR(encryptedString, 32)
26-
console.log('Decrypted: ', decryptedString)
23+
export { XOR }
24+
25+
26+
// Nb: Node REPL might not output the null char '\x00' (charcode 0)
27+
28+
// > XOR('test string', 32)
29+
// 'TEST\x00STRING'
30+
31+
// > XOR('TEST\x00STRING', 32)
32+
// 'test string'

0 commit comments

Comments
 (0)