Jump to content
Open

Cryptography challenges

Recommended Posts

Posted (edited)

Sa se faca un decrypter in limbajul de programare: PHP pentru codul de mai jos


316448404440128472388128460388432468464388128448404128464444464420184

Stiind 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 by Open
  • Upvote 1
Posted

<?php
$arr = str_split("316448404440128472388128460388432468464388128448404128464444464420184", 3);
array_walk($arr, function(&$nr) {
$nr=chr($nr/4);
});
print(implode($arr));
?>

Posted (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 by totti93
Posted

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);

?>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...