-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
187 lines (158 loc) · 7.61 KB
/
index.php
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<html>
<head>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<script type='text/javascript' src='assets/js/bootstrap.min.js'></script>
<meta charset="UTF-8">
<title>Caesar Cipher</title>
</head>
<body>
<div class="col-12 p-3 bg-info text-white">
<div class="row">
<div class="col">
Caesar Cipher Encryptor/Decryptor
</div>
<div class="col text-right">
Dibuat dengan sepenuh hati menggunakan PHP
</div>
</div>
</div>
<div class="col-12 p-3 bg-light text-dark" style="padding-bottom: 100px">
<div class="container">
<blockquote class="blockquote text-center" style="margin: 100px 0px">
<p class="mb-0">Caesar cipher adalah enkripsi berbasis karakter paling sederhana dengan metode pertukaran atau subtitusi sebanyak berdasarkan offset, dimana tiap 1 karakter diganti dengan karakter yang berada di n (offset) digit sebelah kanan atau kirinya, tergantung arah pergeserannya.</p>
<footer class="blockquote-footer">Caesar Cipher</footer>
</blockquote>
<form action="index.php" method="get">
<div class="input-group mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Text :</span>
</div>
<textarea class="form-control" name="text"><?php if (isset($_GET['text'])) echo $_GET['text']; ?></textarea>
</div>
</div>
<p>pilih offset : </p>
<select name="offset" size="1">
<option value="<?php if (isset($_GET['offset'])) {print_r($_GET['offset']);} else {echo "0";} ?>"><?php if (isset($_GET['offset'])) {print_r($_GET['offset']);} else {echo "0";} ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
</select>
<div class="text-center">
<button type="Encrypt" name="encrypt" class="btn btn-primary btn-lg">Encrypt</button>
<button type="Decrypt" name="decrypt" class="btn btn-primary btn-lg">Decrypt</button>
</div>
</form>
</div>
<div class="container text-center" style="margin-top:100px; margin-bottom: 100px">
<h1 class="display-4">
Result :
</h1>
<p class="lead">
<?php
function encrypt($str, $offset) {
$encrypted_text = "";
$offset = $offset % 26;
if($offset < 0) {
$offset += 26;
}
$i = 0;
while($i < strlen($str)) {
$c = strtoupper($str{$i});
if(($c >= "A") && ($c <= 'Z')) {
if((ord($c) + $offset) > ord("Z")) {
$encrypted_text .= chr(ord($c) + $offset - 26);
} else {
$encrypted_text .= chr(ord($c) + $offset);
}
} else {
$encrypted_text .= " ";
}
$i++;
}
return $encrypted_text;
}
function decrypt($str, $offset) {
$decrypted_text = "";
$offset = $offset % 26;
if($offset < 0) {
$offset += 26;
}
$i = 0;
while($i < strlen($str)) {
$c = strtoupper($str{$i});
if(($c >= "A") && ($c <= 'Z')) {
if((ord($c) - $offset) < ord("A")) {
$decrypted_text .= chr(ord($c) - $offset + 26);
} else {
$decrypted_text .= chr(ord($c) - $offset);
}
} else {
$decrypted_text .= " ";
}
$i++;
}
return $decrypted_text;
}
if (isset($_GET['encrypt']))
{
$text = $_GET['text'] ;
$offset = $_GET['offset'] ;
$new_text = encrypt($text , $offset) ;
echo $new_text ;
}
else if (isset($_GET['decrypt']))
{
$text = $_GET['text'] ;
$offset = $_GET['offset'] ;
$new_text = decrypt($text , $offset) ;
echo $new_text ;
}
?>
</p>
</div>
</div>
<div class="col-12 p-3 bg-dark text-white text-center">
<!-- Footer -->
<footer class="page-footer font-small blue">
<!-- Copyright -->
<div class="footer-copyright text-center ">© 2020 Copyright:
<a href="https://t.me/Roooodie"> Sultan Baharuddin Ulil Amrie</a>
</div>
<div class="footer-copyright text-center">Dibuat untuk Mata Kuliah: Cyber Security
</div>
<div class="footer-copyright text-center ">Dosen Mata Kuliah:
<a href="https://scholar.google.com/citations?hl=en&user=xgBf4toAAAAJ"> Irfan Syamsuddin, ST, PG.Dipl.BEC, M.Com.ISM,Ph.D</a>
</div>
<div class="footer-copyright text-center ">Program Studi:
<a href="http://tkj.poliupg.ac.id/">D4 Teknik Komputer dan Jaringan</a>
</div>
<!-- Copyright -->
</footer>
<!-- Footer -->
</div>
</body>
</html>