-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesar2.php
109 lines (108 loc) · 3.59 KB
/
caesar2.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
<?php
##
## This code is licensed under the GPL-v3
## Belongs to the "encrypt" system that can be found here:
## https://github.com/CaeSpock/encrypt
## Questions and suggestions are always welcomed. Send me an E-Mail at: CAnibarro<at>WhiteSith<dot>com
##
// Cesar cipher Type 2 - Cesar 1 1st variation
if ($enckey==0 or !isset($enckey)) {
echo "<div class=\"alert alert-danger\">\n";
echo "<strong>$l_alert!</strong> $l_noksent\n";
echo "</div>\n";
} else {
if ($phrase == "" or !isset($phrase)) {
echo "<div class=\"alert alert-danger\">\n";
echo "<strong>$l_alert!</strong> $l_nopsent\n";
echo "</div>\n";
} else {
echo "<div class=\"table-responsive\">\n";
echo "<table class=\"table table-sm\">\n";
echo "<tr>\n";
echo " <td class=\"table-dark text-right\">$l_type:</td>\n";
echo " <td>$l_caesar2 - K=$enckey</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td class=\"table-dark text-right\">$l_alphabet:</td>\n";
echo " <td><pre>";
for ($i=65; $i<=90; $i++) {
echo chr($i);
}
echo "</pre></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td class=\"table-dark text-right\">$l_newalphabet:</td>\n";
echo " <td><pre>";
for ($i=65; $i<=90; $i++) {
$position=$i;
if ($i>(90-$enckey)) { $position=($i+$enckey-(26+$enckey)); }
$letter=$position+$enckey;
echo chr($letter);
}
echo "</pre></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td class=\"bg-warning text-right\"><strong>$l_phrase:</strong></td>\n";
echo " <td><pre>$phrase</pre></td>";
echo "</tr>\n";
echo "<tr>\n";
echo " <td class=\"bg-success text-right\"><strong>$l_newphrase:</strong></td>\n";
echo " <td><pre>";
$counter=0;
$enckeyesimo = 0;
while ($counter < strlen($phrase)) {
if ( ($enckeyesimo == $enckey) and ($counter > 0)) {
$azar=rand(65,90);
if ($caesar2_cu==1) {
echo "<font color=\"#800000\"><u>".chr($azar)."</u></font>";
} else {
echo chr($azar);
}
$enckeyesimo = 0;
}
$position = ord($phrase[$counter]);
if ($position >=65 and $position<=90) {
if ($position > (90-$enckey)) {
$position= $position+$enckey-(26);
} else {
$position = $position + $enckey;
}
}
echo chr($position);
$counter++;
$enckeyesimo++;
}
echo "</pre></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td class=\"bg-danger text-right\"><strong>$l_inverted:</strong></td>\n";
echo " <td><pre>";
$counter=0;
$enckeyesimo = 0;
while ($counter < strlen($phrase)) {
if ($enckeyesimo != $enckey) {
$position = ord($phrase[$counter]);
if ($position >=65 and $position<=90) {
if ($position < (65+$enckey)) {
$position = $position - $enckey +26;
} else {
$position = $position - $enckey;
}
}
echo chr($position);
} else {
$enckeyesimo = -1;
}
$counter++;
$enckeyesimo++;
}
echo "</pre></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
}
}
echo "<br /><br />";
echo "<div class=\"text text-center\">\n";
echo "<a href=\"$phpself\" class=\"btn btn-secondary\" role=\"button\">$l_goback</a>\n";
echo "</div>";