-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibrary.php
More file actions
77 lines (72 loc) · 3.02 KB
/
library.php
File metadata and controls
77 lines (72 loc) · 3.02 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
if(isset($_POST['encrypt'])){
$text = htmlentities($_POST['textToEncrypt']);
$textToEncrypt = $text;
if($text != ''){
$arr2 = str_split($text);
// echo count($arr2);
$loop = rand(10,20);
// echo $loop;
//array of characters
$arr1 = array('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','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',',','.','-','=','+','`','@','#','$','%','^','&','*','(',')','/',' ');
$encryptedText = '';
for($a = 0; $a < count($arr2); $a++){
$letter = $arr2[$a];
for($b = 0; $b < $loop; $b++){
$pos = array_search($letter,$arr1);
$index = $pos-1;
if($index < 0) $index = count($arr1)-1;
$letter = $arr1[$index];
}
$encryptedText .= $arr1[$index];
}
//translate this to letters
$lpar = str_split($loop);
$ps1 = $arr1[$lpar[0]];
$ps2 = $arr1[$lpar[1]];
$prefix = $ps1.$ps2;
// echo $prefix;
$encryptedText = $prefix.$encryptedText;
}
else{
$encryptedText = 'An error occured!';
}
}
else if(isset($_POST['decrypt'])){
$text = htmlentities($_POST['encryptedText']);
$encryptedText = $text;
if($text != ''){
$arr2 = str_split($text);
// echo count($arr2);
//array of characters
$arr1 = array('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','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',',','.','-','=','+','`','@','#','$','%','^','&','*','(',')','/',' ');
//how many times do I have to loop?
$prefix = str_split(substr($text,0,2));
$ps1 = array_search($prefix[0],$arr1);
$ps2 = array_search($prefix[1],$arr1);
// $ps1--;
// $ps2--;
$loop = $ps1.$ps2;
// echo '<br />here: '.$loop.'<br />';
$txt = substr($text,2,strlen($text));
// echo $text.' - '.$txt;
$split = str_split($txt);
$textToEncrypt = '';
for($a = 0; $a < count($arr2); $a++){
$letter = $arr2[$a];
for($b = 0; $b < $loop; $b++){
$pos = array_search($letter,$arr1);
$index = $pos+1;
if($index > count($arr1)-1) $index = 0;
$letter = $arr1[$index];
}
$textToEncrypt .= $arr1[$index];
}
$textToEncrypt = substr($textToEncrypt,2,strlen($textToEncrypt));
$encryptedText = '';
}
else{
$encryptedText = 'An error occured!';
}
}
?>