Open Posted February 14, 2015 Report Posted February 14, 2015 (edited) Sa se faca un decrypter in limbajul de programare: PHP pentru codul de mai jos316448404440128472388128460388432468464388128448404128464444464420184Stiind ca $encrypted .= (ord($character) * 4);Premiu: Pun la bataie un tricou personalizat sau o sticla de JB. Cea mai ingenioasa rezolvare este castigatoare.----------------------------------------------------------------------------------------------------------Timp concurs: 2 zile. Mai exact Luni 15.02.2015 se afiseaza castigatorul.----------------------------------------------------------------------------------------------------------N-are rost sa prezint functia care decrypteaza acel mesaj, postez direct functia care face cryptarea, mai jos aveti functii peste functii de decryptare.Success!public function Encrypt($message) { $characters = str_split($message); $encrypted = ''; foreach ($characters as $character) { $encrypted .= (ord($character) * 4) . ''; } return $encrypted; }----------------------------------------------------------------------------------------------------------Cei care au rezolvat: @pr00f----------------------------------------------------------------------------------------------------------Castigatorul premiului:Sunt doi care mi-au atras atentia, deocamdata inca mai ma gandesc!---------------------------------------------------------------------------------------------------------- Edited February 18, 2015 by Open 1 Quote
Byte-ul Posted February 14, 2015 Report Posted February 14, 2015 <?php$arr = str_split("316448404440128472388128460388432468464388128448404128464444464420184", 3);array_walk($arr, function(&$nr) { $nr=chr($nr/4);});print(implode($arr));?> Quote
totti93 Posted February 14, 2015 Report Posted February 14, 2015 (edited) Iterativa:function decrypt($enc) { for ($v = str_split($enc, 3); $i < sizeof($v); $dec .= chr($v[(int) $i] >> 2), $i++); return $dec;}Recursiva:function decrypt($enc) { return $enc ? chr(substr($enc, 0, 3) >> 2) . decrypt(substr($enc, 3)) : '';}L.E.: A, da, sunt niste variabile nedeclarate (ca sa scriu mai putin), deci:ini_set('display_errors', FALSE); Edited February 14, 2015 by totti93 Quote
pr00f Posted February 14, 2015 Report Posted February 14, 2015 Pacat ca ord() nu lucreaza pe utf-8, altfel implementarea pentru 255 ar fi fost mai amuzanta .Metoda `babeasca', evitarea split-ului folosit mai sus:<?php$encrypted = "316448404440128472388128460388432468464388128448404128464444464420184";function dec($enc) { $dec = ""; for ($i=0; $i<strlen($enc); $i+=3) $dec .= chr(($enc[$i].$enc[$i+1].$enc[$i+2])/4); return $dec;}echo dec($encrypted);?> Quote
Open Posted February 18, 2015 Author Report Posted February 18, 2015 TOPIC CLOSEVoi reveni cu un edit pentru a anunta castigatorul, deocamdata sunt indecis. Quote