一个java解密算法改写为php解密算法的代码

java了解的太基础了,反正改写解密算法够了,这个解密算法也挺简单的。于是就写了下,将java改为php版本的


public class Jincon {

    public static void main(String []args) {
        String [] names ={"解密的密文"};
        for( String name : names ) {
          System.out.print( name );
          System.out.print(",");
          Decrypt(name) ;
          System.out.print("\n");
        }
    }

    public static int DecodeChar(String str, int i) throws NumberFormatException
    {
        return Integer.parseInt(str.substring(i, i + 2), 16);
    }
    public static String Decrypt(String str)
    {
        String encoderText = "lsdfoglkwjemc-091324jlkmsda-0sd=1234;l;lsdkOPIER203-4LKJSLDJAS0D925JKNNC,MANSLDJQ32ELK1N4SAIp089er0234lkjo9df82l3kjlknf,nzxc,mn;lasdj9wquelq;d]qowe[;wq;qkwellsdkfj0-0POPOAR0W8RPOp-02@#$sdklj$#)0asdlksadLKJFA9820934)(&$3ij09sdj34-sdfj2po345-09dlkfjlkv,mxncv;laskdkl/a;au093hakjh2389~!@%&*%#&^539478(*&)^(&^_*8-*_+++|78w3ihsdnmnclksdj)(*#%*_@$(+#@$)&@#^*&^#@$()(*#@$HDFIkdhfgkjh098k;ldsk.sdv.c,msd;flkp0w34;2lk-=sd0p121o39-werl2k3;4lj09sdflskjlekfj,mv,mcxvjlksjdflksjdl*(#@!&akhduyqweperilmmdxcasnd*(#@9879327kjhasudfewr kwehriwueyrhc ausdgiq7w8e71 cdsh93ol2q32879y8932qwhdkjanhdskjaoe*&w#jh$)(*dsFshc na89wue32e981yewher12(*&#quds)(*i3o1928osaihdaklsdkalkduqowe3290874kljhklasdhlijhqweio4hwe89(*$#$eriho349oij(#*q$OIJHO)(&*#$_)(IUDSOIUoiOIUSAODFU034liusdrogiuet0lsdmc,.mg;lq-091lk3l;kjsdf--123098fe*(JOKJSFD983345oihjdp0(#*$&#@!HKJH!(@#*&ioysdk@#)uhOA7E98R7239845K(*&(#@*$&HKFDJHWERYIWoi)(*&#@&^%@!dsfoi;.;,p[osklejr230897*(&we2&^%@78*(&#@!(7~&*~^@*&^#(*&auroiqkjwrhoasdf89qlrlkjpour09werk23jh";
        int seed, pre;
        try
        {
            seed = DecodeChar(str, 0);
        }
        catch (NumberFormatException e)
        {
            return "";
        }
        try
        {
            pre = DecodeChar(str, 2);
        }
        catch (NumberFormatException e)
        {
            return "";
        }

        pre = pre & 3;

        String ret = "";
        int x;
        int i, j;
        int len = str.length();
        int elen = encoderText.length();
        for (i = pre + pre + 4, j = seed; i < len; i += 2)
        {
            try
            {
                x = DecodeChar(str, i);
                System.out.print(x);
                System.out.print("\n");
            }
            catch (NumberFormatException e)
            {
                return "";
            }
            int intValue = encoderText.charAt(j);
            x ^= intValue;
            char ch = (char) x;
            ret += ch;
            if (++j >= elen)
                j = 0;
        }
        return ret;
    }
}


对应的php:

<?php
function DecodeChar($str,$i){
    return hexdec(substr($str,$i, 2));
}
function Decrypt($str){
    $encoderText = 'lsdfoglkwjemc-091324jlkmsda-0sd=1234;l;lsdkOPIER203-4LKJSLDJAS0D925JKNNC,MANSLDJQ32ELK1N4SAIp089er0234lkjo9df82l3kjlknf,nzxc,mn;lasdj9wquelq;d]qowe[;wq;qkwellsdkfj0-0POPOAR0W8RPOp-02@#$sdklj$#)0asdlksadLKJFA9820934)(&$3ij09sdj34-sdfj2po345-09dlkfjlkv,mxncv;laskdkl/a;au093hakjh2389~!@%&*%#&^539478(*&)^(&^_*8-*_+++|78w3ihsdnmnclksdj)(*#%*_@$(+#@$)&@#^*&^#@$()(*#@$HDFIkdhfgkjh098k;ldsk.sdv.c,msd;flkp0w34;2lk-=sd0p121o39-werl2k3;4lj09sdflskjlekfj,mv,mcxvjlksjdflksjdl*(#@!&akhduyqweperilmmdxcasnd*(#@9879327kjhasudfewr kwehriwueyrhc ausdgiq7w8e71 cdsh93ol2q32879y8932qwhdkjanhdskjaoe*&w#jh$)(*dsFshc na89wue32e981yewher12(*&#quds)(*i3o1928osaihdaklsdkalkduqowe3290874kljhklasdhlijhqweio4hwe89(*$#$eriho349oij(#*q$OIJHO)(&*#$_)(IUDSOIUoiOIUSAODFU034liusdrogiuet0lsdmc,.mg;lq-091lk3l;kjsdf--123098fe*(JOKJSFD983345oihjdp0(#*$&#@!HKJH!(@#*&ioysdk@#)uhOA7E98R7239845K(*&(#@*$&HKFDJHWERYIWoi)(*&#@&^%@!dsfoi;.;,p[osklejr230897*(&we2&^%@78*(&#@!(7~&*~^@*&^#(*&auroiqkjwrhoasdf89qlrlkjpour09werk23jh';
    $seed=$pre=0;
    $seed = DecodeChar($str, 0);
    $pre = DecodeChar($str, 2);
    $pre = $pre & 3;
    $ret = "";
    $x=$i=$j=0;
    $len = strlen($str);
    $elen = strlen($encoderText);
    for ($i = $pre + $pre + 4, $j = $seed; $i < $len; $i += 2)
    {
        $x = DecodeChar($str, $i);
        $intValue = ord($encoderText{$j});
        $x = $x^$intValue;
        $ch = chr($x);
        $ret .= $ch;
        if (++$j >= $elen)
            $j = 0;
    }
    return $ret;
}
echo Decrypt('解密密文');

?> 

关键词: java , php , 解密算法

上一篇: openresty+Lua构建高性能、高可靠、安全的登陆校验
下一篇: PHP+jQuery实现的大转盘抽奖程序

目前还没有人评论,您发表点看法?
发表评论

评论内容 (必填):