只想将代码解码为纯文本 [英] Just want to decode the code into plain text

查看:145
本文介绍了只想将代码解码为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想了解更多有关使用128位编码的函数get_rnd_iv()和md5_encrypt()的信息.现在,我们只想知道如何将该代码解码为纯文本...

We would like to know more about function get_rnd_iv() and md5_encrypt() these function for using 128bit encoding. Now here we just want to know how to decode that code into plain text...

这是我所有的代码行.

function get_rnd_iv($iv_len)
{
   $iv = '';
   while ($iv_len-- > 0) {
       $iv .= chr(mt_rand() & 0xff);
   }
   return $iv;
}

function md5_encrypt($plain_text, $password, $iv_len = 16)
{
   $plain_text .= "\x13";
   $n = strlen($plain_text);
   if ($n % 16) $plain_text .= str_repeat("\0", 16 - ($n % 16));
   $i = 0;
   $enc_text = get_rnd_iv($iv_len);
   $iv = substr($password ^ $enc_text, 0, 512);
   while ($i < $n) {
       $block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv));
       $enc_text .= $block;
       $iv = substr($block . $iv, 0, 512) ^ $password;
       $i += 16;
   }
   return base64_encode($enc_text);
}

function md5_decrypt($enc_text, $password, $iv_len = 16)
{
   $enc_text = base64_decode($enc_text);
   $n = strlen($enc_text);
   $i = $iv_len;
   $plain_text = '';
   $iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512);
   while ($i < $n) {
       $block = substr($enc_text, $i, 16);
       $plain_text .= $block ^ pack('H*', md5($iv));
       $iv = substr($block . $iv, 0, 512) ^ $password;
       $i += 16;
   }
   return preg_replace('/\\x13\\x00*$/', '', $plain_text);
}
?>

推荐答案

我们想进一步了解函数get_rnd_iv()和md5_encrypt()

We would like to know more about function get_rnd_iv() and md5_encrypt()

但是您不会说您想知道的是什么!

But you don't say what it is that you want to know!

有一个_encrypt()_decrypt()-有什么问题?

There's an _encrypt() and a _decrypt() - what's the problem?

我不是cryptoanalyst-但是函数的名称非常错误-md5是哈希函数而不是加密函数-即md5的要点是使数据不可解密-当然,这种对称算法使用的是md5函数-但是它不仅仅实现md5.

I'm no cryptoanalyst - but the functions are very badly named - md5 is a hashing function NOT an encryption function - i.e. the point of md5 is to make the data un-decryptable - certainly this symmetric algorithm is using an md5 function - but it doesn't implement just md5.

IV的意义在于,使用相同的密钥加密相同的消息会产生不同的输出(因此使重放攻击和密钥标识更加困难).注意,需要生成IV进行加密,并将相同的值传递给解密fn.对于您提供的代码,该代码已合并到输出中-但可以单独处理.

The point of an IV is so that encrypting the same message with the same key gives a different output (and hence makes replay attacks and key identification more difficult). NB the IV needs to be generated for encrpytion and the same value passed to the decryption fn. In the case of the code you've provided it is being incorporated into the output - but can be handled separately.

我可能是错的,但是这里的算法看起来像是 WEP

I could be wrong, but the algorithm here looks like a variation on WEP

这篇关于只想将代码解码为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆