В интернете есть интересные вещи ... Мне понравилось this one за его простоту (простые подстановочные шифры), поэтому я позаимствовал его и немного изменил. Мне также пришлось написать часть декодирования, но это было легко ;-)
Это дает интересные результаты.
Выше результат ... заинтересован в коде или в расшифрованной значение? затем прочитайте ниже:
(так как вы будете получать электронные письма, у вас будет ключ ... Я думаю, это будет довольно легко реализовать в любом коде отправки электронной почты. Чтение расшифрованных сообщений будет более сложным, я представьте себе самый простой способ будет создать GMAIL фильтр, чтобы присвоить метку к этим сообщениям и оттуда написать приложение, чтобы прочитать их с помощью функции декодирования.)
function test(){
var key = "#@&é,?(§è!çà)-_°$*^¨`£ù%=+MPLOKIJUHYGTFRDESZQANBVCXW";
Logger.log(encode(key,'My name is bond, James Bond'));
Logger.log(decode(key,encode(key,'My name is bond James Bond')));
}
function encode(key, message)
// Given : key is a string of the 52 letters in arbitrary order (2 x 26 characters),
// message is the string to be encoded using the key
// Returns: the coded version of message using the substitution key
{
var alphabet, coded, i, ch, index;
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
coded = "";
for (i = 0; i < message.length; i++) { // for as many letters as there are
ch = message.charAt(i); // access the letter in the message
index = alphabet.indexOf(ch); // find its position in alphabet
if (index == -1) { // if it's not a letter,
coded = coded + ch; // then leave it as is & add
} // otherwise,
else { // find the corresponding
coded = coded + key.charAt(index); // letter in the key & add
}
}
return coded;
}
function decode(key, message){
var alphabet, decoded, i, ch, index;
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
decoded = "";
for (i = 0; i < message.length; i++) { // for as many letters as there are
ch = message.charAt(i); // access the letter in the message
index = key.indexOf(ch); // find its position in key
if (index == -1) { // if it's not in the key,
decoded = decoded + ch; // then leave it as is & add
} // otherwise,
else { // find the corresponding
decoded = decoded + alphabet.charAt(index);// letter in the alphabet & add
}
}
return decoded;
}
вы можете форматировать код, чтобы сделать его немного более читаемый –
это помогает? – user2374110