question:
one English word is known. The English word contains only the uppercase letters "Amurz" and the lowercase letters "Amurz". Your task is to translate English words into cipher text. The rule of translation is to replace all letters with the third letter after it, and assume that the character an is followed by the character z and the character An is followed by the character Z. For example, zero will be translated into chur.
input and output requirements:
enter an English word, each of which is no more than 100 in length, and the word ends with the carriage return newline character"n". Output the password text of the corresponding string, accounting for one line.
Program running effect:
Sample 1:
zero
chur
Sample 2:
AZazbf
DCdcei
Code:
the general idea is: get the ASC code value of each English character, add 3 bits back, and deal with other things that are out of range
<body>
<input type="text" id="letter" />
<button id="result"></button>
<script>
window.onload = function() {
var letter = document.getElementById("letter");
var result = document.getElementById("result");
var upperMin = 65; //asc
var upperMax = 90; //asc
var lowerMin = 97; //asc
var lowerMax = 122; //asc
result.onclick = function() {
var s = [];
var letterStr = letter.value;
if(!/[a-zA-Z]/.test(letterStr)) {
alert("");
return;
}
for(var i=0; i<letterStr.length; iPP) {
var _code = letterStr[i].charCodeAt(); //asc
var _move = _code+3; //3
//asc90 12223
if((/[A-Z]/.test(letterStr[i])&&_move > upperMax) || (/[a-z]/.test(letterStr[i])&&_move > lowerMax)) {
//asc23
_move = _code - 23;
}
s.push(String.fromCharCode(_move));
}
alert(s.join(""))
}
}
</script>
</body>
is there a better way to implement it than this?