Answer the question
In order to leave comments, you need to log in
How to write a decoder if the algorithm is known?
Hello, I'm curious how to make decoders based on an existing algorithm?
I am doing this for informational purposes.
There is an encoder code, I want to get, as it were, an inverse function (Just like in math analysis)
function shifr(text) {
var alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяӘІҢҒҮҰҚӨҺәіңғүұқөһ";
var key = getkey();// 'nx9MwEJN2KZ6e1NPiCAaHTxn9QX0iXcjLUoY9fdpc6J';
var len = alphabet.length;
var table = new Array();
for (var i = 0; i < len; i++) {
table[i] = alphabet.substring(i) + alphabet.substring(0, i);
}
var word = text;
var shfr = "";
while (key.length < word.length)
key += key;
for (var i = 0; i < word.length; i++) {
if (alphabet.indexOf(word[i]) > -1) {
shfr = shfr + table[alphabet.indexOf(key[i])][alphabet.indexOf(word[i])];
}
else
shfr = shfr + word[i];
}
return shfr;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question