zoukankan      html  css  js  c++  java
  • 一个加密算法

    using System;

    namespace test001
    {
     /**

     据说此加密算法每次加密的结果都不同,但解密的结果相同
       对sSource,进行加密、解密操作。
       @param sSource String :操作的字符串
       @param iFlag int :操作类型 1-加密  2-解密
       @return String :加密或解密后的字符串
        **/
     public class password
     {
      public password()
      {
      }
      public static string pWord(string sSource,int iFlag)
      {
       if(sSource==null)
        return null;
       if(sSource.Equals(""))
        return "";
       int li_len,i,li_asc,li_rand,li_head;
                string ls_i,ls_code="";
       if(iFlag ==1)
       {
        li_len=sSource.Length;
        Random rdm1 = new Random(~unchecked((int)DateTime.Now.Ticks));
        li_head=(int)(rdm1.NextDouble()*10);
        if(li_head ==0)
         li_head =1;
        for(i=0; i<li_len; i++)
        {
         Random rdm2 = new Random(~unchecked((int)DateTime.Now.Ticks));
         int rand2 =(int)(rdm2.NextDouble() *94);
         if(rand2 ==0)
          rand2 =1;
         li_rand=rand2+32;
         li_asc=Convert.ToInt32(sSource.ToCharArray(i,1)[0]);
         ls_i=((char)(li_asc -i)).ToString();

         if(li_asc+i+li_head>126)
         {
          if(li_rand%2 ==1)
           li_rand=li_rand+1;
          ls_i=((char)(li_rand)).ToString()+((char)(li_asc -i -li_head)).ToString();
         }
         else
         {
          if(li_rand%2 ==0)
           li_rand=li_rand+1;
          ls_i=((char)(li_rand)).ToString()+((char)(li_asc +i +li_head)).ToString();
         }
         ls_code=ls_code+ls_i;
        }
        Random rdm3 = new Random(~unchecked((int)DateTime.Now.Ticks));
        int rand1 =(int)(rdm3.NextDouble()*9);
        if(rand1 ==0)
         rand1 =1;
        ls_code=((char)(rand1*10+li_head+40)).ToString()+ls_code;
       }
       else
       {
        int li_ret;
        li_len=sSource.Length;
        ls_code="";
        li_ret=Convert.ToInt32(sSource.ToCharArray(0,1)[0]) %10;
        for( i=2;i <li_len; i=i+2)
        {
         li_asc=Convert.ToInt32(sSource.ToCharArray(i,1)[0]);
         if(Convert.ToInt32(sSource.ToCharArray(i - 1,1)[0]) %2 ==0)
         {
          ls_i=((char)(li_asc + (i - 1)/2 + li_ret)).ToString();
         }
         else
         {
          ls_i=((char)(li_asc - (i - 1)/2 - li_ret)).ToString();
         }
         ls_code=ls_code+ls_i;
        }
       }
       return ls_code;
      }
     }
    }

  • 相关阅读:
    FAQ: c++ 函数名后添加 const void function1(int &id) const
    FAQ: C++中定义类的对象:用new和不用new有何区别?
    How to create a project with existing folder of files in Visual Studio?
    How to export a template in Visual Studio?
    t4 multiple output sample
    fastjson1.2.48以下版本存在重大漏洞
    一秒完成springboot与logback配置
    统计greenplum_postgresql数据占用存储情况
    上传文件不落地转Base64字符串
    三个标签完成springboot定时任务配置
  • 原文地址:https://www.cnblogs.com/0000/p/1600804.html
Copyright © 2011-2022 走看看