Last active
September 16, 2017 19:56
-
-
Save korniychuk/a19c3a493d13b104be60e56cdb0732b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Encoder</title> | |
<script> | |
var numberSystem = +prompt('Введите систему счисления(число от 2 до 36):', '16'); | |
if (numberSystem >= 2 && numberSystem <= 36) { | |
var data = prompt('Введите данные для обработки:'); | |
var isEncode = confirm('Что сделать? ок - закодировать, отмена - раскодировать'); | |
var res; | |
var isCorrect = true; | |
if (isEncode) { | |
res = String(data).split('').map((char) => char.codePointAt(0).toString(numberSystem)).join(' '); | |
} else { | |
var numbers = String(data).split(' ').map((i) => parseInt(i, numberSystem)); | |
isCorrect = numbers.every((i) => !isNaN(i)); | |
if (isCorrect) { | |
res = numbers.map((i) => String.fromCodePoint(i)).join(''); | |
} | |
} | |
if (isCorrect) { | |
alert('Результат:' + res); | |
} else { | |
alert('Не корректный шифр!'); | |
} | |
} else { | |
alert('Вы ввели не правильную систему счисления!'); | |
} | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment