1.

<HTML>

2.

<HEAD>

3.

<TITLE>Stage One of Encryption</TITLE>

4.

<SCRIPT LANGUAGE = "Javascript">

5.

 

6.

var W, i, S;

7.

 

8.

 

9.

function Begin()

10.

{ var i, A,B,S, T, Number, Length, M, First, Second, Third, Fourth;

11.

W = document.EncryptForm.Phrase.value;

12.

 

13.

Length = W.length;

14.

 

15.

S = "It has " + Length + " characters.";

16.

Append = "That is an odd number. I will append an X to the end and proceed with the encryption."

17.

 

18.

 

19.

 

20.

if (W.length % 2 == 1)

21.

{ S = S + Append;

22.

W = W + "X";

23.

Length = Length + 1 }

24.

 

25.

var Originals = new Array(Length/2);

26.

 

27.

document.EncryptForm.Comment.value = S;

28.

 

29.

T = "Its original numerical representation is ";

30.

document.EncryptForm.Digits.value = T;

31.

 

32.

for (i = 0; i < Length ; i = i + 2)

33.

{ A = W.charCodeAt(i) ;

34.

B = W.charCodeAt(i+1) ;

35.

Number = 100*A + B;

36.

Originals[i/2] = Number;

37.

}

38.

 

39.

document.EncryptForm.plain.value = Originals.join(" ");;

40.

 

41.

var Scrambleds = new Array (Length/2);

42.

var Digits = new Array(4)

43.

 

44.

function power(k)

45.

{ var i, N;

46.

N = 1;

47.

for (i = 1; i <= k; i = i+ 1) N = N * 10;

48.

return N;

49.

}

50.

 

51.

for (i = 0; i < Length/2; i = i + 1)

52.

{

53.

M = Originals[i];

54.

for (j = 0; j <= 3; j = j+ 1)

55.

{ Digits[j] = Math.floor(M/power(j));

56.

Digits[j] = ( Digits[j] + 7) % 10; }

57.

M = 0;

58.

for (j = 0; j <= 3; j = j+ 1)

59.

M = M + Digits[j] * power(3-j);

60.

 

61.

 

62.

Scrambleds[i] = M

63.

}

64.

 

65.

document.EncryptForm.Scrambled.value = Scrambleds.join(" ");

66.

 

67.

 

68.

}

69.

 

70.

71.

</SCRIPT>

72.

</HEAD>

73.

<BODY BGCOLOR = "white">

74.

<FORM NAME = "EncryptForm">

75.

Enter a word or phrase <INPUT NAME = "Phrase" SIZE = 80 TYPE = "text">

76.

<BR>

77.

<INPUT TYPE = "button" VALUE = "Click to Encrypt" SIZE = "20"

78.

ONCLICK = "Begin()" >

79.

<BR>

80.

<TEXTAREA NAME = "Comment" ROWS =4 COLS = 50 TYPE = "text"> </TEXTAREA>

81.

<BR>

82.

<INPUT NAME = "Digits" SIZE = 50 TYPE = "text">

83.

<BR>

84.

<TEXTAREA NAME = "plain" ROWS = 5 COLS = 50 TYPE = "text"> </TEXTAREA>

85.

<BR>

86.

<H2>The encrypted message is:

87.

<BR>

88.

<TEXTAREA NAME = "Scrambled" ROWS = 5 COLS = 50 TYPE = "text">

89.

</TEXTAREA>

90.

</FORM>

91.

</BODY>

92.

</HTML>