-
Notifications
You must be signed in to change notification settings - Fork 0
/
vigenere2.html
57 lines (56 loc) · 2.05 KB
/
vigenere2.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Dekódolás</title>
</head>
<body>
<div>
<p>Kódolt szöveg</p><input type="text" onfocus="clir1()" id="text">
<p>Kulcs</p><input type="text" id="key">
<input type="submit" onclick="othername();">
<p id="ki"></p>
</div>
<script>
function clir1() {
document.getElementById('ki').innerHTML='';
document.getElementById('text').value='';
document.getElementById('key').value='';
}
function szokoz(x){
var x = x.split('');
var i;
for (i=x.length-1;i>=0;i--){
if (x[i] == ' ' || x[i] == '.' || x[i] == '?' || x[i] == ',' || x[i] == '!'){
x.splice(i,1);
}
}
x=x.join('');
return x;
}
function othername() {
var text = szokoz(document.getElementById("text").value).toLowerCase();
var key = szokoz(document.getElementById("key").value).toLowerCase();
var i = 0;
while (key.length < text.length){
key += key.charAt(i % key.length);
i++;
}
var abc = ['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 a = abc;
var abc = ['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 result='';
for (i=0; i<key.length; i++){
while (a[0] != key.charAt(i)){
a.push(a[0]);
a.splice(0, 1);
}
result += abc[a.indexOf(text[i])];
}
//window.alert(result);
document.getElementById("ki").innerHTML = "Az eredmény: " + result;
}
</script>
</body>
</html>