Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function hexToStr($hex)
- {
- $string='';
- for ($i=0; $i < strlen($hex)-1; $i+=2)
- {
- $string .= chr(hexdec($hex[$i].$hex[$i+1]));
- }
- return $string;
- }
- function convert($text, $key = '') {
- // return text unaltered if the key is blank
- if ($key == '') {
- return $text;
- }
- // remove the spaces in the key
- $key = str_replace(' ', '', $key);
- if (strlen($key) < 8) {
- exit('key error');
- }
- // set key length to be no more than 32 characters
- $key_len = strlen($key);
- if ($key_len > 32) {
- $key_len = 32;
- }
- // A wee bit of tidying in case the key was too long
- $key = substr($key, 0, $key_len);
- // We use this a couple of times or so
- $text_len = strlen($text);
- // fill key with the bitwise AND of the ith key character and 0x7C, padded to length of text.
- $lomask = str_repeat("\x7C", $text_len); // Probably better than str_pad
- $himask = str_repeat("\x00", $text_len);
- $k = str_pad("", $text_len, $key); // this one _does_ need to be str_pad
- // {en|de}cryption algorithm
- $text = (($text ^ $k) & $lomask) | ($text & $himask);
- return $text;
- }
- echo convert(hexToStr('5E5C535C584B40584A4A4E564B5D4503510755020402080C580A015D0D0A5A010206070C0E025C000F005D080E5F5D'), '1234567899999999');
- echo "\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement