开发者

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 "".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜