@@ -746,7 +746,7 @@ const encrypted = 65 + (char + key) % 65 % 26
746746Additional functionality can be added by allowing the argument to be an array of keys:
747747
748748` ` ` js
749- const allShifts = [... Array (26 ).keys ()]
749+ const allShifts = [... Array (25 ).keys ()]. map ( n => n + 1 )
750750const cipher = (str , keys = allShifts ) => {
751751 ...
752752 const res = keys .map ( key => {
@@ -759,6 +759,8 @@ Putting it all together:
759759
760760` ` ` js
761761const allShifts = [... Array (26 ).keys ()]
762+
763+ // return all possible shifts if keys not given
762764const cipher = (str , keys = allShifts ) => {
763765 const chars = str .split (" " )
764766 const res = keys .map ( key => {
@@ -780,9 +782,29 @@ const cipher = (str, keys=allShifts) => {
780782 })
781783 return res .map ( (r , i ) => { return { key: keys[i], result: r .join (" " ) } } )
782784}
785+
786+ cipher (" JavaScript" , [1 , 2 , 27 ])
787+ /* [{ key: 1, result: 'KbwbTdsjqu' },
788+ { key: 2, result: 'LcxcUetkrv' },
789+ { key: 27, result: 'KbwbTdsjqu' }]*/
790+
791+ cipher (" Something" )
792+ /* [{ key: 1, result: 'Tpnfuijoh' },
793+ { key: 2, result: 'Uqogvjkpi' },
794+ { key: 3, result: 'Vrphwklqj' },
795+ { key: 4, result: 'Wsqixlmrk' },
796+ ......,
797+ { key: 20, result: 'Migynbcha' },
798+ { key: 21, result: 'Njhzocdib' },
799+ { key: 22, result: 'Okiapdejc' },
800+ { key: 23, result: 'Pljbqefkd' },
801+ { key: 24, result: 'Qmkcrfgle' },
802+ { key: 25, result: 'Rnldsghmf' }
803+ ]
804+ */
783805` ` `
784806
785- And that's the easiest encryption ever!
807+ And that's the easiest encryption ever! Happy Coding!
786808</p>
787809<hr>
788810<hr>
0 commit comments