簡體   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