doushi3454 2014-11-26 20:01
浏览 30

在php中使用BCCMATH库根据操作系统给出不同的结果

here is my problem. I am using BCMATH functions of PHP (here the class I use, and the function Base_Math::obfuscate()) to obfuscate some urls, ids, etc and deobfuscate them.

I am actually programming over windows 8.1 x64 with the last version of XAMPP. Recently I created a virtual machine in my computer wtih vmware based on centOS 6.6 x64 which is the operative system I will have online, to debug problems compabilities between operative system and to have a stage environment to make updates faster.

The problem comes when I go to the vm environment, the functions used from BCMATH gives me as a result different values as it does in windows environment. One of my friends warn me about this could happen but I love risk and lose tons of hours programming :|

What I don't know, if this problem comes because of the operative system, because of the hardware itself or what? Can I modified the function so it gives me back always the same result? If it can't be what would you say it is a good solution to obfuscate your database entities ID?

This is the way I use the method:

//obfuscate number 5
Math_Base::obfuscate(5,false,32,'OndZLj3mby9GpDtbrzDVGPkWR1J1dlC9JPIcsMe1l0YX8lzONTVlkCzDzPb9PJR');
//it returns on windows 8: CsQNlnY5dXMKJXYLFgzxZT85HTzPb2FQ 
//in centos YBs1DMzFdhV5JhzlG7NvtxfFmxNkrTGs
  • 写回答

1条回答 默认 最新

  • douweiduo7526 2014-11-27 19:47
    关注

    Thanks to @Cheery because what he/she said gave me the answer to the problem in the third comment of my question. It was all about srand(). Since I didn't create this class, my great friend did modified it for me. This is the result class

    He did change this part (causing the problem):

     if ($this->_key !== null) {
         //Mezclar los caracteres base usando la clave
         srand(crc32($this->_key));
         $this->_base = str_shuffle($this->_base_original);
         srand(); //Restaurar semilla aleatoria por defecto
     }
    

    For this one:

    if ($this->_key !== null) {
        //Mezclar los caracteres base usando la clave
        mt_srand(crc32($this->_key));
        $chars = Str::chars($this->_base_original);
        for($i = count($chars) - 1; $i > 0; --$i) {
            $j = mt_rand(0, $i);
            if($i !== $j) {
                list($chars[$i], $chars[$j]) = array($chars[$j], $chars[$i]);
            }
        }
        $this->_base= join('', $chars);
        mt_srand();//Restaurar semilla aleatoria por defecto
    }
    

    So he did avoid any compatibility problem between platforms.

    Thanks to everyone who helped here.

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)