このコードが正しく機能するようになっています。 Pythonにもっと精通しています - 新しいjavascript。これは私のpythonの同等のもののようだった:javascript(ASCIIコード付き)を使用したhtmlのCaesar Cipherが必要です
userinput = input("Enter the message you want to encryppt: ")
shift = int(input("How many letters do you want to shift by? "))
empty = ""
for char in userinput:
a = ord('a') if char.islower() else ord('A')
if char.isalpha():
firstord = ord(char) - a
realord = firstord + shift
realord = realord % 26
realord = realord + a
alpha = (chr(realord))
empty = empty + alpha
else:
notalpha = ("?")
empty = empty + notalpha
print(empty)
以下は、JavaScriptのバージョンです - 私はコメントを使用しました。私はちょっと別にそれを設定しました。 (最後のブロックはhtmlです)何らかの理由で、ボタンと入力ボックスしか表示されませんが、出力は表示されません。ヘルプ
<script>
function enterName(){
\t var userName = document.getElementById("word_in").value; //get the input string from the page
\t var shiftBy = Number(document.getElementById("shift").value); \t //get the amount of shift and convert it into a number. This Is IMPORTANT
\t var size= userName.length; \t \t \t \t \t \t \t \t \t \t //get the size of the input string
\t var encrypt="";
\t var temp = 0;
\t var i=0;
\t
\t //step through the string 1 character at a time
\t for (i=0; i<size; i++){
\t
\t //store the ASCII value of each character
\t \t temp=userName.charCodeAt(i){
\t \t // Uppercase
\t \t if ((temp >= 65) && (temp <= 90)){
\t \t \t temp = (((temp - 65 + shiftBy) % 26) + 65);
\t \t }
\t \t // Lowercase
\t \t else if ((temp >= 97) && (temp <= 122)){
\t \t \t temp = (((temp - 97 + shiftBy) % 26) + 97);
\t \t }
\t \t else {
\t \t \t temp = "?";
\t \t }
\t \t \t
\t \t }
\t \t encrypt += String.fromCharCode(temp) \t
\t } \t
\t \t
\t //output to the page
\t document.getElementById("word_out").innerHTML = encrypt;
}
</script>
<body>
<p>Please enter your name:</p>
<input id="word_in">
<p>Please enter the shift:</p>
<input id = "shift">
<button type = "button" onclick="enterName()"></button>
<p id = "word_out"></p>
</body>
それはそれのような単純なものかもしれないと思った - ありがとう – user6113119