繁体   English   中英

用 JavaScript 混淆和替换字母

[英]Obfuscating and replacing the Alphabets with JavaScript

我正在寻找一种混淆字母表的方法。 我所说的“混淆字母表”的具体意思是用第二个数组字母替换输入字母。 例如,我想替换这个数组(第二个数组)中的所有字母: ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; 使用这个数组:

["z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "m", "l", "k", "j", "i", "h", "g", "f", "e", "d", "c", "b", "a"]所以如果我输入的字母是 "abc",那么 output 字母就是 "zyx"。

看来您自己已经找到了答案。 这是寻找基本替代 cypher 的其他人的选项:

 const substitutionCypher = (input) => { // input should be a string; do your own validation const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); const cypherbet = 'zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA'.split(''); const resultArray = input.split('').map(char => { return (alphabet.includes(char))? cypherbet[alphabet.indexOf(char)]: char; }); return resultArray.join(''); } // Example usage: console.log(substitutionCypher('hello;@#5638 WORLD! 83929$$'));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM