Is there a lib for this kind of crypt/decrypt in python? I am trying to generate encrypted ascii text which changes on each generation.
If no lib for this, would you please advice a working alternative. Already tried to convert this PHP code to python but I failed.
PHP what I use at the moment:
function keyED($txt,$encrypt_key)
{
$ctr=0;
$tmp = "";
$txt_len=strlen($txt);
for ($i=0;$i<$txt_len;$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}
function encrypt($txt,$key)
{
srand((double)microtime()*1000000);
$encrypt_key = md5(rand(0,32000));
$ctr = 0;
$tmp = "";
$txt_len = strlen($txt);
for ($i=0;$i < $txt_len;$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) . (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return keyED($tmp,$key);
}
function decrypt($txt,$key)
{
$txt = keyED($txt,$key);
$tmp = "";
$txt_len=strlen($txt);
for ($i=0;$i<$txt_len;$i++)
{
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}
$x = encrypt("test", "123");
echo decrypt($x, "123") // -> "test"