class Encryption
{
const DEFAULT_NUMBER= 1000000;
const ENCODING = 'UTF-16';
public static function encrypt($text, $num) {
$text = strval($text);
$encrypted_text = '';
foreach (str_split($text) as $symbol) {
$encrypted_text .= mb_chr(mb_ord($symbol, self::ENCODING) + $num, self::ENCODING);
}
return base64_encode($encrypted_text);
}
public static function decrypt($encrypted_text, $num) {
$encrypted_text = base64_decode($encrypted_text);
$decrypted_text = '';
foreach (str_split($encrypted_text) as $symbol) {
$decrypted_text .= mb_chr(mb_ord($symbol, self::ENCODING) - $num, self::ENCODING);
}
return $decrypted_text;
}
}
$enc = \App\Encryption\Encryption::encrypt('Hello World!', 1000000);
$dec = \App\Encryption\Encryption::decrypt($enc, 1000000);
var_dump($enc, $dec);