Дарья87,
без коментариев ...
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<script>
function crypt(message) {
var a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
message = message.split("");
return message.reduce(function(message, current) {
var i = a.indexOf(current);
i = "00000" + i.toString(2);
i = i.slice(-5);
i = i.replace(/\d/g, function(a) {
return ["A", "B"][a]
});
return message + i
}, "")
}
function decrypt(message) {
var a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
message = message.match(/.{5}/g);
return message.reduce(function(message, current) {
current = current.replace(/./g, function(a) {
return {
"A": "0",
"B": "1"
}[a]
});
current = parseInt(current, 2);
return message + a[current]
}, "")
};
document.write(crypt("RAMMSTEIN")+"<br>")
document.write(decrypt("BAAABAAAAAABBAAABBAABAABABAABBAABAAABAAAABBAB")+"<br>")
</script>
</body>
</html>