forked from joeolaoye/monocypher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCypher.php
More file actions
56 lines (52 loc) · 1.06 KB
/
Cypher.php
File metadata and controls
56 lines (52 loc) · 1.06 KB
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
<?php
class Cypher
{
private static $enc = array(
'a' => 'Q',
'b' => 'W',
'c' => 'E',
'd' => 'R',
'e' => 'T',
'f' => 'Y',
'g' => 'U',
'h' => 'I',
'i' => 'O',
'j' => 'P',
'k' => 'A',
'l' => 'S',
'm' => 'D',
'n' => 'F',
'o' => 'G',
'p' => 'H',
'q' => 'J',
'r' => 'K',
's' => 'L',
't' => 'Z',
'u' => 'X',
'v' => 'C',
'w' => 'V',
'x' => 'B',
'y' => 'N',
'z' => 'M'
);
public static function doEncryption($s)
{
$s = preg_replace("/[^a-z]/i", "", $s);
$s = str_split($s);
foreach ($s as &$c) {
$c = self::$enc[$c];
}
unset($c);
return implode("", $s);
}
public static function doDecryption($s)
{
$s = str_split($s);
foreach ($s as &$c) {
$key = array_search($c, self::$enc);
$c = $key;
}
unset($c);
return implode("", $s);
}
}