Also habe ich diese Chiffre gemacht und im Moment, wenn ich 'a' mit einer Verschiebung von 1 eintippe gibt es 'b' aus Das ist richtig, aber wenn ich 'ab' oder eine andere Länge der Saite einfüge, wird 'bl' zum Beispiel gesetzt. Wie behebe ich das?Wie kommt es, dass meine Chiffre immer nur den ersten Buchstaben korrekt verschlüsselt, aber nicht den zweiten, dritten usw.
function encryption(str, amount) {
var str = document.getElementById('inputText').value;
var amount = document.getElementById('amountDropdown').value;
var result = "";
//loop through each character in word
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
//If the character is uppercase
if ((c >= 65) && (c <= 90)) {
result += String.fromCharCode(((c - 65 + amount) % 26) + 65);
}
//if the character is lowercase
else if ((c >= 97) && (c <= 122)) {
result += String.fromCharCode(((c - 97 + amount) % 26) + 97);
}
//if the character isn't a letter
else {
result += str.charAt(i);
}
}
//return the result
outputResult.innerHTML = "The text you have input has been encrypted to.." + result;
}
function decryption() {
var str = document.getElementById('inputText').value;
var amount = document.getElementById('amountDropdown').value;
var result = "";
//loop through each character in word
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
//If the character is uppercase
if (c >= 65 && c <= 90) {
result += String.fromCharCode((c - 65 - amount) % 26 + 65);
}
//if the character is lowercase
else if (c >= 97 && c <= 122) {
result += String.fromCharCode((c - 97 - amount) % 26 + 97);
}
//if the character isn't a letter
else {
result += str.charAt(i);
}
}
//return the result
outputResult.innerHTML = "The text you have input has been encrypted to.." + result;
}
function encryptClickHandler() {
document.getElementById('inputText').value = encrypt(document.getElementById('inputText').value, document.getElementById('amount').value);
}
function decryptClickHandler() {
document.getElementById('inputText').value = decrypt(document.getElementById('inputText').value, document.getElementById('amount').value);
}