-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.php
More file actions
31 lines (29 loc) · 782 Bytes
/
cipher.php
File metadata and controls
31 lines (29 loc) · 782 Bytes
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
<?php
class Cipher {
public $string;
public $values = array();
public $length;
function __construct($string){
$this->string = strtolower(str_replace(' ', '', $string ));
$this->length = strlen($this->string);
$abc = range('a', 'z');
for( $i = 0 ; $i < $this->length ; $i++ ){
for($num=0; $num < 26; $num++){
if ($this->string[$i] == $abc[$num]){
$this->values[$i] = $num;
}
}
}
}
}
$key = new Cipher($_POST['key']);
$text = new Cipher($_POST['message']);
$abc = range('a', 'z');
while($key->length < $text->length){
$key->values = array_merge($key->values, $key->values);
$key->length = count($key->values);
}
for($i=0; $i < $text->length; $i++){
echo $abc[($key->values[$i] + $text->values[$i])%26];
}
?>