PHP, to adapt to the post simple encryption of ciphertext
Copy Code code as follows:
<?php
Replacement from previous versions of cryptographic replacements
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 Code code 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;
}