|
);
var strPassPhrase = document.PassForm.strPass.value;
var lenPassPhrase = strPassPhrase.length;
var strPlainText = strCrypt[ordName*2];
var strSantaText = strCrypt[ordName*2+1];
var lenSantaText = strSantaText.length;
var lenPlainText = strPlainText.length;
var strMyAlphabet = "$Aa1Bb2Cc3Dd4Ee5Ff6Gg7Hh8Ii9Jj0Kk LlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
var lenMyAlphabet = strMyAlphabet.length;
var ordIllegalPassCharIndex = 1;
var strNewPassPhrase = "";
for (i=0;i<lenPassPhrase;i++)
{ ordPassPhraseChar = strMyAlphabet.indexOf(strPassPhrase.charAt(i));
if ((0==ordPassPhraseChar) || (-1==ordPassPhraseChar))
{ ordPassPhraseChar = ordIllegalPassCharIndex++;
if (ordIllegalPassCharIndex >= lenMyAlphabet)
{ ordIllegalPassCharIndex = 1;
}
}
strNewPassPhrase += strMyAlphabet.charAt(ordPassPhraseChar);
}
strPassPhrase = strNewPassPhrase; //alert( strPassPhrase );
var strCryptText = "";
for (i=0;i<lenPlainText;i++)
{ ordPassPhraseChar = strMyAlphabet.indexOf(strPassPhrase.charAt(i%lenPassPhrase));
ordPlainTextChar = strMyAlphabet.indexOf(strPlainText.charAt(i));
ordCryptTextChar = (ordPassPhraseChar ^ ordPlainTextChar) % lenMyAlphabet;
strCryptText += strMyAlphabet.charAt( ordCryptTextChar );
}
document.OutputForm.strOutput.value = strCryptText;
strCryptText = "";
for (i=0;i<lenSantaText;i++)
{ ordPassPhraseChar = strMyAlphabet.indexOf(strPassPhrase.charAt(i%lenPassPhrase));
ordPlainTextChar = strMyAlphabet.indexOf(strSantaText.charAt(i));
ordCryptTextChar = (ordPassPhraseChar ^ ordPlainTextChar) % lenMyAlphabet;
strCryptText += strMyAlphabet.charAt( ordCryptTextChar );
}
document.SecretSantaForm.strSecretSanta.value = strCryptText;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
My educational background is Mathematics, Physics and Computer Science. I also earned a secondary teaching certificate.
My professional background is as a Software Engineer for the past 25 years or so and before that an instructor of Mathematics and Computer Science at the college level.
I currently design, develop, and support standards based Application Programming Interfaces that allow Windows based applications to interact with financial devices in a vendor neutral manner.
My hobbies are cycling, playing with the Internet, and reading.