hi all fairly new to javascript, anyway am trying to develop an app that encrypts and decrypts text.
the idea is to encrypt only consonants based on it location within a word by assigning each letter a value (its unique key) based on its location, rather than on every occurrence of the letter within a message.
so for example in these words = Webmaster talk; for webmaster the values would be W=1, b=3, m=4, s=6, t=7, r=9 but in talk they would be t=1, l=3, k=4.
I have already sorted out the vowel script which simply goes to the next vowel based on the input key (it was a deal more simpler to think through than the consonants) and is included below just in case it has any relevance. I also set up a simple form html which inputs the text and key but not sure if you would need it.
anyway thanks in advance for any help or tips i recieve
Code:
<!-- Begin
var wt = ""; //temporary holder
var et = ""; //encoded text
var all = "";
var all2 = "";
var vowel2 = "aeiou";
var a = "a";
var e = "e";
var i = "i";
var o = "o";
var u = "u";
var vowel = new Array('a', 'e', 'i', 'o', 'u');
function encode() {
wt = "";
et = "";
all = "";
var theText = document.f1.ta1.value.toLowerCase();
var num = document.f1.tb1.value;
i2 = 0;
for (i = 0; i < num; i++) {
i2 = i2 + 1;
if (i2 == 5) i2 = 0;
}
a = vowel[i2]; i2 = next(i2);
e = vowel[i2]; i2 = next(i2);
i = vowel[i2]; i2 = next(i2);
o = vowel[i2]; i2 = next(i2);
u = vowel[i2]; i2 = next(i2);
var all = a+e+i+o+u;
all = all.split("");
encode2(all);
}
function next(x) {
if (x == 4) x = -1;
x = x + 1;
return x;
}
function encode2(all2) {
var temp2 = document.f1.ta1.value.toLowerCase();
temp2 = temp2.split("");
var q = 0;
while (q < temp2.length) {
wt = temp2[q];
var where = vowel2.indexOf(wt);
if (where == -1) { et += wt; }
if (where != -1) { et += all2[where]; }
q = q + 1;
}
document.f1.ta1.value = et;
}
function decode() {
wt = "";
et = "";
all = "";
all3 = "";
var theText = document.f1.ta1.value.toLowerCase();
var num = document.f1.tb1.value;
i2 = 0;
for (i = 0; i < num; i++) {
i2 = i2 + 1;
if (i2 == 5) i2 = 0;
}
a = vowel[i2]; i2 = next(i2);
e = vowel[i2]; i2 = next(i2);
i = vowel[i2]; i2 = next(i2);
o = vowel[i2]; i2 = next(i2);
u = vowel[i2]; i2 = next(i2);
var all = a+e+i+o+u;
all3 = all;
all = all.split("");
decode2(all3);
}
function decode2(all2) {
var vowel2 = "aeiou";
vowel2 = vowel2.split("");
var temp2 = document.f1.ta1.value.toLowerCase();
temp2 = temp2.split("");
var v = 0;
while (v < temp2.length) {
wt = temp2[v];
var where = all2.indexOf(wt);
if (where == -1) { et += wt; }
if (where != -1) { et += vowel2[where]; }
v = v + 1;
}
document.f1.ta1.value = et;
}
// End -->
|