Decryption function
I have this function which decrypts encrypted message. First letter in the encrypted text is a signal character.
function decryptWord(cipherText, indexCharacter, plainAlphabet, cipherAlphabet)
{
var signalCharacter = cipherText.charAt(0);
var decryptedString;
cipherAlphabet = rotateToPosition(signalCharacter, indexCharacter, plainAlphabet, cipherAlphabet);
for (var count = 1; count<cipherText.length; count++)
{
var singleLetter = cipherText.charAt(count);
var i = cipherAlphabet.indexOf(singleLetter);
decryptedString = decryptedString + plainAlphabet[i];
}
return decryptedString;
}
I'm looking for word JAVASCRIPT as a result b开发者_如何学Cut i get 'undefinedJAVASCRIPT' is that because when the first loop is being carried out there is no value assigned to decryptedString? is there a way to go around it? Thanks.
Exactly right, try initialising decryptedString
to ""
.
精彩评论