PHP, adapted to the post-simple encryption of ciphertext
Copy CodeThe code is as follows:
Replacement encryption replacement from the previous version
function Compress_func ($match) {return strlen ($match [0]). $match [0]{0};}
function Uncompress_func ($match) {return str_repeat ($match [2], $match [1]);}
function Compress ($STR) {
$i = 0;
$pattern = Array ();
while (Isset ($replacement {$i})) Array_push ($pattern, "/". $replacement {$i + +}. " {2,}/");
Return Preg_replace_callback ($pattern, "Compress_func", $str);
}
function Uncompress ($STR) {
Return Preg_replace_callback ("/(d+) (W)/", "Uncompress_func", $str);
}
?>
AWK, General format
Copy CodeThe code is as follows:
#!/bin/awk
function compress (str, _argvend_, str_out, Str_len, I, S, l) {
Str_out = "";
Str_len = Length (str);
s = "";
L = 1;
for (i =1; I <= str_len; i++) {
if (substr (str, I, 1) = = = s) l++;
else {
if (s! = "") {
if (L > 1) str_out=str_out "" L
Str_out=str_out "" s;
}
s = substr (str, I, 1);
L = 1;
}
}
return str_out;
}
function uncompress (str, _argvend_, str_out, Str_len, I, c) {
Str_out = "";
Str_len = Length (str);
for (i =1; I <= str_len; i++) {
c = 0;
while (substr (str, I, 1) ~/[0-9]/) {
c = c*10+substr (str, I, 1);
i++;
}
if (c < 1) c = 1;
while (c--) str_out = Str_out "" substr (str, I, 1);
}
return str_out;
}
http://www.bkjia.com/PHPjc/319046.html www.bkjia.com true http://www.bkjia.com/PHPjc/319046.html techarticle PHP, adapted to the post-simple encryption of the ciphertext copy code code is as follows:? PHP//replacement from the previous version of the encryption replacement Functioncompress_func ($match) {returnstrlen ($match [0] ). $mat ...