-
Notifications
You must be signed in to change notification settings - Fork 3
/
CipherOne
74 lines (62 loc) · 1.79 KB
/
CipherOne
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<style>
body{
background-color:#66ff66;
}
h1{
text-align:center;
}
.Button_Style{
background-color:#ff99bb;
width:100px;
height:30px;
font-size:14pt;
border: 2px solid black;
}
</style>
</head>
<body>
<h1>Secret Messages</h1>
<h3>Encryption</h3>
<p>Please enter a message and a key</p>
<table>
<tr>
<td>Please enter your message</td>
<td><input type="text" id="strMessage" name="strMessage" width="150px;"></td>
</tr>
<tr>
<td>Please enter your key</td>
<td><input type="text" id="strKey" name="strKey" width="150px;"></td>
</tr>
</table>
<input type="button" id="btn_Encrypt" name="btn_Encrypt" value="Click Me" onclick="fn_TestFunction();" class="Button_Style">
<script type="text/javascript">
function fn_TestFunction(){
//code goes here
var strMessage = document.getElementById('strMessage').value;
var strKey = document.getElementById('strKey').value;
var aryAlphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var strEncoded = '';
var intNewKey = 0;
for(var i=0; i < strMessage.length; i++){
//code
for(var x = 0; x < aryAlphabet.length; x++){
if(strMessage[i] == aryAlphabet[x]){
intNewKey = x + parseInt(strKey);
if(intNewKey >= aryAlphabet.length){
//if we're encoding y, then x will be equal to 24
// x + 2 = 26. 26 is greater than the length of our array
//we change x to be equal to x - 26 which will give us 0
//So y is encoded to a as a is the 1st element
intNewKey = intNewKey - aryAlphabet.length;
}
strEncoded = aryAlphabet[intNewKey];
alert("Found a match: " + strEncoded);
}
}
}
}
</script>
</body>
<html>