首页 > 开发 > 综合 > 正文

最简单的字符串加密C#实现-移位加密

2024-07-21 02:25:01
字体:
来源:转载
供稿:网友
 

/*
  filename: encrypt_string.cs
  author : zhanghua
  date  : 2005-08-11
  fuction : input a strig  and encrypt a string
            加密后的字符串的第一个字符是原先字符串的最后一个字符,
            其余的每一个字符是对应的原字符串中的前一个字符的值加
            上3。
            example: welcome -> ezhofrp
        
*/
using system;

class test
{
 public static void main()
 {
  string strinput, stroutput;
  
  console.writeline("please input a string to encrypt: /n");
  strinput=console.readline();

  
  console.writeline(" your input string is : {0}/n", strinput);
   //encrypt(strinput);
  
  stroutput = encrypt(strinput);
 
   console.writeline("stroutput is :{0}/n", stroutput);
 }
  
  private static string  encrypt(string  strinput)
  {
   string strfont,  strend;
   string stroutput;
   char[] charfont;
   int i,len, intfont;
   
   len = strinput.length;
   //console.writeline(" strinput 's length is :{0} /n", len);
   strfont = strinput.remove(len-1,1);                                 
   strend= strinput.remove(0, len-1);                                 
                                
   //console.writeline(" strfont is : {0} /n" , strfont);                                 
   //console.writeline(" strend is : {0} /n" , strend);                                 
                                 
     charfont = strfont.tochararray();                                 
   for(i=0; i<strfont.length; i++)                                 
   {                                 
    intfont = (int)charfont[i] + 3;                                 
    //console.writeline(" intfont is : {0} /n", intfont);                                 
                                     
    charfont[i]= convert.tochar(intfont);                                   
    //console.writeline("charfont[{0}] is : {1}/n", i, charfont[i]);                                 
   }
     strfont = ""; //let strfont  null
   for (i=0; i<charfont.length; i++)
   {
      strfont += charfont[i];
    } 
     stroutput=strend + strfont;
     return stroutput;
   
  }
}


菜鸟学堂:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表