Skip to content

Commit 6ea0fa5

Browse files
committed
English version files
1 parent a67e840 commit 6ea0fa5

File tree

3 files changed

+339
-0
lines changed

3 files changed

+339
-0
lines changed

en/index.html

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
6+
<!-- Meta -->
7+
<meta charset="UTF-8" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
9+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
10+
11+
<!-- PACE -->
12+
<script src="./../pace/pace.js"></script>
13+
<link rel="stylesheet" href="./pace/pace.css" />
14+
15+
<!-- Bootstrap CSS -->
16+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
17+
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />
18+
19+
<!-- My style -->
20+
<link rel="stylesheet" href="./../style.css" />
21+
22+
<!-- Switch -->
23+
<link rel="stylesheet" href="./../switch.css" />
24+
25+
<!-- Icon -->
26+
27+
<!-- Title -->
28+
<title>Anon's Webpage</title>
29+
30+
</head>
31+
32+
<body>
33+
34+
<!-- Main site code -->
35+
<div class="container">
36+
37+
<div id="alerts"></div>
38+
39+
<div class="row">
40+
<div class="col-12">
41+
42+
<div class="flag">
43+
<a href="./../en/">
44+
<div class="en"></div>
45+
</a>
46+
</div>
47+
48+
<div class="flag">
49+
<a href="./../pl/">
50+
<div class="pl"></div>
51+
</a>
52+
</div>
53+
54+
</div>
55+
</div>
56+
57+
<div class="row">
58+
<div class="col text-center">
59+
<header>
60+
<h1>Encrypting application</h1>
61+
<h2>Caesar cipher</h2>
62+
</header>
63+
</div>
64+
</div>
65+
66+
<div class="row">
67+
68+
<div class="col-md-6 col-lg-4">
69+
<div class="input-box text-center">
70+
<textarea id="cipher-input" placeholder="Input your text to encrypt..." autofocus
71+
required></textarea>
72+
</div>
73+
</div>
74+
75+
<div class="col-md-6 col-lg-4">
76+
<div class="input-box text-center">
77+
<div class="row">
78+
<div class="col-12">
79+
<p class="pt-0 mt-4 mb-5">Please input number of characters to skip</p>
80+
</div>
81+
<div class="col-12">
82+
<input type="number" id="cipher-number" max="35" min="1" placeholder="1-35" required />
83+
</div>
84+
</div>
85+
</div>
86+
</div>
87+
88+
<div class="col-md-12 col-lg-4">
89+
<div class="input-box text-center">
90+
<div class="row">
91+
<div class="col-8 text-center">
92+
<p class="mt-4">Encrypt / Decrypt</p>
93+
</div>
94+
<div class="col-4">
95+
<label class="switch">
96+
<input type="checkbox" />
97+
<span class="slider round" id="cipher-switch"></span>
98+
</label>
99+
</div>
100+
</div>
101+
<div class="row">
102+
<div class="col">
103+
<div class="text-center">
104+
<button type="submit" id="cipher-submit" class="bg-button">Encrypt!</button>
105+
</div>
106+
</div>
107+
</div>
108+
</div>
109+
</div>
110+
111+
<div class="col">
112+
<div class="input-box text-center">
113+
<p id="cipher-output" class="read-code d-inline-block">Encrypted text will show here</p>
114+
</div>
115+
</div>
116+
117+
</div>
118+
119+
<div class="row">
120+
<div class="col">
121+
<footer>
122+
Author: Jakub Suchenek &copy;
123+
</footer>
124+
</div>
125+
</div>
126+
127+
</div>
128+
129+
<!-- jQuery slim -->
130+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
131+
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
132+
crossorigin="anonymous"></script>
133+
134+
<!-- Popper -->
135+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
136+
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
137+
crossorigin="anonymous"></script>
138+
139+
<!-- Bootstrap -->
140+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
141+
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
142+
crossorigin="anonymous"></script>
143+
144+
<!-- Cipher script -->
145+
<script src="./script.js"></script>
146+
147+
</body>
148+
149+
</html>

en/script.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
document.getElementById('cipher-submit').addEventListener('click', cipher);
2+
document.getElementById('cipher-switch').addEventListener('click', cipherSwitch);
3+
4+
var cipherState = 'encrypt';
5+
6+
function cipherSwitch() {
7+
let cipherSubmitInfo = document.getElementById('cipher-submit');
8+
if (cipherState == 'encrypt') {
9+
cipherState = 'decrypt';
10+
cipherSubmitInfo.textContent = 'Decrypt!';
11+
console.log('Now decrypting');
12+
return;
13+
} else {
14+
cipherState = 'encrypt';
15+
cipherSubmitInfo.textContent = 'Encrypt!';
16+
console.log('Now encrypting');
17+
return;
18+
};
19+
};
20+
21+
22+
23+
function cipher() {
24+
25+
var cipherError = 'Unknown error!';
26+
27+
let cipherOutput = document.getElementById('cipher-output');
28+
let cipherInput = document.getElementById('cipher-input').value;
29+
let cipherInputBox = document.getElementById('cipher-input');
30+
let cipherNumber = parseInt(document.getElementById('cipher-number').value, 10);
31+
let cipherNumberBox = document.getElementById('cipher-number');
32+
33+
function showError() {
34+
let newError = document.createElement('div');
35+
newError.classList = 'd-block my-alert absolute-top alert alert-danger';
36+
37+
let closeButton = document.createElement('a');
38+
closeButton.setAttribute('href', '#');
39+
closeButton.classList = 'close';
40+
closeButton.setAttribute('data-dismiss', 'alert');
41+
closeButton.setAttribute('aria-label', 'Close');
42+
closeButton.innerHTML = '&times;';
43+
newError.appendChild(closeButton);
44+
45+
let errorText1 = document.createElement('strong');
46+
errorText1.textContent = 'Warning! ';
47+
newError.appendChild(errorText1)
48+
49+
let errorText2 = document.createElement('span');
50+
errorText2.textContent = cipherError;
51+
newError.appendChild(errorText2);
52+
53+
document.getElementById('alerts').appendChild(newError);
54+
window.scrollTo({ top: 0, behavior: 'smooth' });
55+
};
56+
57+
let alfabeth = [
58+
'A',
59+
'B',
60+
'C',
61+
'D',
62+
'E',
63+
'F',
64+
'G',
65+
'H',
66+
'I',
67+
'J',
68+
'K',
69+
'L',
70+
'M',
71+
'N',
72+
'O',
73+
'P',
74+
'Q',
75+
'R',
76+
'S',
77+
'T',
78+
'U',
79+
'V',
80+
'W',
81+
'X',
82+
'Y',
83+
'Z'
84+
];
85+
86+
cipherInputBox.classList.remove('wrong');
87+
cipherNumberBox.classList.remove('wrong');
88+
89+
// is empty
90+
if ((cipherInput == '') || (cipherInput == ' ')) {
91+
cipherInputBox.classList.add('wrong');
92+
cipherError = 'Text area can\'t be empty!';
93+
showError();
94+
return;
95+
};
96+
97+
// starts with space
98+
if ((cipherInput.charAt(0) == ' ')) {
99+
cipherInputBox.classList.add('wrong');
100+
cipherError = 'Text area can\'t start with space!';
101+
showError();
102+
return;
103+
}
104+
105+
cipherInput = cipherInput.toUpperCase();
106+
107+
// contains not specified characters
108+
for (let i = 0; i < cipherInput.length; i++) {
109+
if (cipherInput.charAt(i) == ' ') {
110+
continue;
111+
} else if (!(alfabeth.includes(cipherInput.charAt(i)))) {
112+
cipherInputBox.classList.add('wrong');
113+
cipherError = 'Text area contains unexpected characters!';
114+
showError();
115+
return;
116+
};
117+
};
118+
119+
// end with space
120+
if (cipherInput.charAt((cipherInput.length - 1)) == ' ') {
121+
cipherInputBox.classList.add('wrong');
122+
cipherError = 'Text area can\'t end with space!';
123+
showError();
124+
return;
125+
};
126+
127+
// does not containt number
128+
if (isNaN(cipherNumber)) {
129+
cipherNumberBox.classList.add('wrong');
130+
cipherError = 'No number provided!';
131+
showError();
132+
return;
133+
};
134+
135+
// number out of range
136+
if ((cipherNumber < 1) || (cipherNumber > 26)) {
137+
cipherNumberBox.classList.add('wrong');
138+
cipherError = 'Number is out of specified index!';
139+
showError();
140+
return;
141+
};
142+
143+
console.log('Processing text - ' + cipherInput);
144+
console.log('With number - ' + cipherNumber);
145+
console.log('Type - ' + cipherState);
146+
147+
// decrypt
148+
if (cipherState == 'decrypt') {
149+
cipherNumber = 26 - cipherNumber;
150+
};
151+
152+
let cipherAlfabeth = alfabeth.slice();
153+
154+
let temp;
155+
for (let i = 1; i <= cipherNumber; i++) {
156+
temp = cipherAlfabeth[0];
157+
cipherAlfabeth.splice(0, 1);
158+
cipherAlfabeth.push(temp);
159+
};
160+
temp = '';
161+
162+
let cipherOutputText = '';
163+
let cipherCharIndex = 0;
164+
for (let i = 0; i < cipherInput.length; i++) {
165+
if (cipherInput.charAt(i) == ' ') {
166+
cipherOutputText += ' ';
167+
} else {
168+
cipherCharIndex = alfabeth.indexOf(cipherInput.charAt(i));
169+
cipherOutputText += cipherAlfabeth[cipherCharIndex];
170+
};
171+
};
172+
cipherOutput.textContent = cipherOutputText;
173+
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
174+
};

img/en.svg

Lines changed: 16 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)