PHP Classes

Wrong results

Recommend this page to a friend!

      EnCryptDe  >  All threads  >  Wrong results  >  (Un) Subscribe thread alerts  
Subject:Wrong results
Summary:I get wrong results using your class
Messages:2
Author:Carlos A. Pérez M.
Date:2011-12-10 16:09:41
Update:2011-12-28 11:32:42
 

 


  1. Wrong results   Reply   Report abuse  
Picture of Carlos A. Pérez M. Carlos A. Pérez M. - 2011-12-10 16:09:41
Hi.

I just downloaded your class and tested with some other data and got wrong results back.

Just run this script and see the results.

<?php
/**
* Newest version always at
* https://gist.github.com/1395302
*/

define('BR',"<br />\n");

include 'Crypter.php';

$Crypter = new Crypter();
$key = 'LbCgRj6uIcOaqvWmZQV253l9Hk0MxeSfDUEFt7yiGr4z1YXAhopTNJBnw';
$Crypter->setScramble2($key);

$str = 'Pure php enCrypt, deCrypt strings';

echo "<p style='margin:0px;'>Your key: $key</p>";
echo "<p style='margin:0px;'>Your string: $str</p>";
$str = $Crypter->encrypt($str);
echo "<p style='margin:0px;'>encrypt result:(<span style='font-weight:bold;'>$str</span>)</p>";
echo "<p style='margin:0px;'>Result after decryption:(<span style='font-weight:bold;'>{$Crypter->decrypt($str)}</span>)</p>";
echo "<p style='margin:0px;font-size:24px;'>Perfect Result</p>";
echo BR.BR;


$str = 'ThisIsSomeDataToTest.something.com.EndDataToTest';
echo "<p style='margin:0px;'>First I tryed some other data with your key</p>";
echo "<p style='margin:0px;'>Original Data:(<span style='font-weight:bold;'>$str</span>)</p>";
$str = $Crypter->encrypt( $str );
echo "<p style='margin:0px;'>encrypt result:(<span style='font-weight:bold;'>$str</span>)</p>";
echo "<p style='margin:0px;'>Result after decryption:(<span style='font-weight:bold;'>{$Crypter->decrypt( $str )}</span>)</p>";
echo "<p style='margin:0px;font-size:24px;'>Wrong Result</p>";
echo BR.BR;

$str = 'Version20101205%@@%Method=POST%@@%Gets=%@@%Prog=SiteSecurity/UserSignOn.php%@@%Chain=6%@@%Next=2%@@%Post=commonNewLang=Es,commonSessKeep=,commonUpdate=Continue,commonBasic=6,commonOrder=1,formIdNumber=3238071,formPassword=,formPasswordMd5=c8a957ee2bf49989341b998b849a9e0b,formVideoKey=,formVideoKeyMd5=%@@%Referer=/VideoHipico/SiteSecurity/UserSignOn.php%@@%RefType=Normal%@@%End=End';
echo "<p style='margin:0px;'>This is a very long string to see just what happens with your key</p>";
echo "<p style='margin:0px;'>Original Data:(<span style='font-weight:bold;'>$str</span>)</p>";
$str = $Crypter->encrypt( $str );
echo "<p style='margin:0px;'>encrypt result:(<span style='font-weight:bold;'>$str</span>)</p>";
echo "<p style='margin:0px;'>Result after decryption:(<span style='font-weight:bold;'>{$Crypter->decrypt( $str )}</span>)</p>";;
echo "<p style='margin:0px;font-size:24px;'>Wrong Result</p>";
echo BR.BR;

$key = 'abcdefghijklmnopqrstuvewxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ.-,;:_';
echo "<p style='margin:0px;'>I thought that maybe there are characters missing in the encryption key so I changed the key to</p>";
echo "<p style='margin:0px;'>$key</p>";
$Crypter->setScramble2($key);

$str = 'ThisIsSomeDataToTest.something.com.EndDataToTest';
echo "<p style='margin:0px;'>First I tryed some other data with the modyfied key</p>";
echo "<p style='margin:0px;'>Original Data:(<span style='font-weight:bold;'>$str</span>)</p>";
$str = $Crypter->encrypt( $str );
echo "<p style='margin:0px;'>encrypt result:(<span style='font-weight:bold;'>$str</span>)</p>";
echo "<p style='margin:0px;'>Result after decryption:(<span style='font-weight:bold;'>{$Crypter->decrypt( $str )}</span>)</p>";
echo "<p style='margin:0px;font-size:24px;'>ALSO Wrong Result</p>";
echo BR.BR;

$str = 'Version20101205%@@%Method=POST%@@%Gets=%@@%Prog=SiteSecurity/UserSignOn.php%@@%Chain=6%@@%Next=2%@@%Post=commonNewLang=Es,commonSessKeep=,commonUpdate=Continue,commonBasic=6,commonOrder=1,formIdNumber=3238071,formPassword=,formPasswordMd5=c8a957ee2bf49989341b998b849a9e0b,formVideoKey=,formVideoKeyMd5=%@@%Referer=/VideoHipico/SiteSecurity/UserSignOn.php%@@%RefType=Normal%@@%End=End';
echo "<p style='margin:0px;'>This is a very long string to see just what happens with your key</p>";
echo "<p style='margin:0px;'>Original Data:(<span style='font-weight:bold;'>$str</span>)</p>";
$str = $Crypter->encrypt( $str );
echo "<p style='margin:0px;'>encrypt result:(<span style='font-weight:bold;'>$str</span>)</p>";
echo "<p style='margin:0px;'>Result after decryption:(<span style='font-weight:bold;'>{$Crypter->decrypt( $str )}</span>)</p>";;
echo "<p style='margin:0px;font-size:24px;'>ALSO Wrong Result</p>";
echo BR.BR;

?>

  2. Re: Wrong results   Reply   Report abuse  
Picture of Vladimir Fesko Vladimir Fesko - 2011-12-28 11:32:42 - In reply to message 1 from Carlos A. Pérez M.
Hi!

The problem is quite simple - your $key is too short. Just make sure that $key is at least as long as RTCrypt::streight is - and you'll get correct results.

Have a nice coding!