-
Notifications
You must be signed in to change notification settings - Fork 0
/
Playing_with_passphrases.js
34 lines (24 loc) · 1.26 KB
/
Playing_with_passphrases.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently they can be guessed due to common cultural references. You can get your passphrases stronger by different means. One is the following:
choose a text in capital letters including or not digits and non alphabetic characters,
shift each letter by a given number but the transformed letter must be a letter (circular shift),
replace each digit by its complement to 9,
keep such
*/as non alphabetic and non digit characters,
downcase each letter in odd position, upcase each letter in even position (the first character is in position 0),
reverse the whole result.
Example:
your text: "BORN IN 2015!", shift 1
1 + 2 + 3 -> "CPSO JO 7984!"
4 "CpSo jO 7984!"
5 "!4897 Oj oSpC"
With longer passphrases it's better to have a small and easy program. Would you write it?
*/
function playPass(s, n) {
let alpha = 'abcdefghijklmnopqrstuvwxyz'
return s.toLowerCase().split('').map( x => {
if(alpha.includes(x))return alpha.indexOf(x)+n > 25 ? alpha[alpha.indexOf(x) + n - 26] : alpha[alpha.indexOf(x) + n]
else if (!/[0-9]/.test(x)) return x
else {return (9 - x) + ''}
}).map( (x,i) => i%2 ? x : x.toUpperCase()).reverse().join('')
}