Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function mt_rand_str ($l, $c = 'abcdefghijklmnopqrstuvwxyz1234567890') {
- for ($s = '', $cl = strlen($c)-1, $i = 0; $i < $l; $s .= $c[mt_rand(0, $cl)], ++$i);
- return $s;
- }
- function encode($text, $key) {
- $strlen = strlen($text);
- $seq = $key;
- $gamma = '';
- while (strlen($gamma) < $strlen) {
- $seq = pack("H*",sha1($gamma.$seq));
- $gamma.=substr($seq,0,8);
- }
- return $text^$gamma;
- }
- $string_var = 'Съешь ещё этих мягких французских булок, да выпей чаю!
- СЪЕШЬ ЕЩЁ ЭТИХ МЯГКИХ ФРАНЦУЗСКИХ БУЛОК, ДА ВЫПЕЙ ЧАЮ.
- The quick brown fox jumps over the lazy dog.
- THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.';
- $password = mt_rand_str(13);
- echo '<!DOCTYPE html><html><head><meta charset="utf-8"><title>КОНЬЯКОВ.ру: Free PHP Function for Reversible Encryption / Простая и надежная PHP функция для обратимого шифрования</title></head><body><p style="background:#D4FFD4;padding:1em;"><b>Source string:</b> '.$string_var.'</p><p style="background:#FFD4D4;padding:1em;"><b>Encode string:</b> (Password: <u>'.$password.'</u>)<br>'.encode($string_var, $password).'</p><p style="background:#7FFFAA;padding:1em;"><b>Decode string:</b> '.encode(encode($string_var, $password), $password).'</p>';
- if ($string_var == encode(encode($string_var, $password), $password)) {
- echo '<p style="background:#00CC00;padding:1em;color:#fff">Source and Decode strings are identical :)</p>';
- } else {
- echo '<p style="background:#FF0000;padding:1em;color:#fff">Source and Decode strings are not identical :(</p>';
- }
- echo '</body></html>';
- ?>
Add Comment
Please, Sign In to add comment