Answer the question
In order to leave comments, you need to log in
How to process arrays?
The problem of multiloop polyalphabetic substitution is given. Given plain text and 2 keys, I can't figure out how to process arrays with this text and keys to get the index of the new character. Screenshot of an example below.
Alphabet:
Answer the question
In order to leave comments, you need to log in
const al = "АБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЫЬЭЮЯ "; // Алфавит
let key1 = "ПЕРВЫЙ"; // первый ключ
let key2 = "БУКВА"; // второй ключ
let open_str = "ЭТО СТРОКА ОТКРЫТОГО ИСХОДНОГО ТЕКСТА"; // кодируемый текст
// т.к. в алфавите нет букв Й и Ъ, то производим соответствующую замену:
key1 = key1.replace("Й","И").replace("Ъ","Ь");
key2 = key2.replace("Й","И").replace("Ъ","Ь");
open_str = open_str.replace("Й","И").replace("Ъ","Ь");
// кодируем текст
let encoded_str = ([...open_str]).map( (e,i) => al[(al.indexOf(e) + al.indexOf(key1[i%key1.length]) + al.indexOf(key2[i%key2.length])) % 32] ).join("");
console.log(encoded_str);
As I understand it:
There is an alphabet with matching codes: 0 - A, 1 - B, 2 - C, 3 - D, etc.
mod is the remainder of the sum divided by 32 (also "mod", sometimes denoted by a percent sign: "% ").
We add the numbers, divide, get the remainder, look at the letter based on the alphabet.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question