public static string DecryptStr( string rs ) //顺序减1解码 
{
byte[] by=new byte[rs.Length];
for( int i=0;
i<=rs.Length-1;
i++ )
{
by[i]=( byte )( ( byte )rs[i]-1 );
}
rs="";
for( int i=by.Length-1;
i>=0;
i-- )
{
rs+=( ( char )by[i] ).ToString( );
}
return rs;
}public static string EncryptStr( string rs ) //倒序加1加密 
{
byte[] by=new byte[rs.Length];
for( int i=0;
i<=rs.Length-1;
i++ )
{
by[i]=( byte )( ( byte )rs[i]+1 );
}
rs="";
for( int i=by.Length-1;
i>=0;
i-- )
{
rs+=( ( char )by[i] ).ToString( );
}
return rs;
}

解决方案 »

  1.   

    自己写了一个解密的,经过调试结果是对的,大家看看有没有什么问题?
    function TForm1.DecryptStr(rs:string):string;
    var
      arrbyte: array[0..20] of Byte;
      str1: string;
      i: Integer;
    begin
      for i := 0 to Length(rs) do
      begin
          arrbyte[i]:= Ord(rs[i])-1;
      end;  for i:=Length(rs) downto 0 do
      begin
       str1:=str1+char(arrbyte[i]);
      end;
        ShowMessage(str1);
      result:=str1;
    end;
      

  2.   


    function DecryptStr( rs:string  ):string; //顺序减1解码
    var
      by:array of byte;
      I,rsLength:integer;
    begin
      rsLength:=length(rs);
      SetLength(by,rsLength);
      for I := 0 to rsLength-1  do
      begin
        by[I]:=Ord(rs[I])-1;
      end;
      rs:='';
      for I := rsLength-1  downto 0 do
      begin
        rs:=rs+char(by[i]);
      end;
      Result:=rs;
    end;function EncryptStr( rs:string  ):string; //倒序加1加密
    var
      by:array of byte;
      I,rsLength:integer;
    begin
      rsLength:=length(rs);
      SetLength(by,rsLength);
      for I := 0 to rsLength-1  do
      begin
        by[I]:=Ord(rs[I])+1;
      end;
      rs:='';
      for I := rsLength-1  downto 0 do
      begin
        rs:=rs+char(by[i]);
      end;
      Result:=rs;
    end;帮你改了下,但运行结果好像是少翻译了最后一位
      

  3.   


    function DecryptStr( rs:string  ):string; //顺序减1解码
    var
      by:array of byte;
      I,rsLength:integer;
    begin
      rsLength:=length(rs);
      SetLength(by,rsLength);
      for I := 0 to rsLength-1  do
      begin
        by[I]:=Ord(rs[I])-1;
      end;
      rs:='';
      for I := rsLength-1  downto 0 do
      begin
        Result:=Result+char(by[i]);
      end;
    end;function EncryptStr( rs:string  ):string; //倒序加1加密
    var
      by:array of byte;
      I,rsLength:integer;
    begin
      rsLength:=length(rs);
      SetLength(by,rsLength);
      for I := 0 to rsLength  do
      begin
        by[I]:=Ord(rs[I])+1;
      end;
      rs:='';
      for I := rsLength  downto 0 do
      begin
        Result:=Result+char(by[i]);
      end;
    end;可以用了(包括汉字和其它字符),呵呵
      

  4.   

    简化一下:
    function DecryptStr(rs: String): String;
    var
      I, L: Integer;
    begin
      L := Length(rs);
      SetLength(Result, L);
      for I := 1 to L do
        Result[I] := chr(ord(rs[L - I + 1]) - 1);
    end;function EncryptStr(rs: String): String;
    var
      I, L: Integer;
    begin
      L := Length(rs);
      SetLength(Result, L);
      for I := 1 to L do
        Result[I] := chr(ord(rs[L - I + 1]) + 1);
    end;
      

  5.   

    再简化一下//顺序减1解码
    function DecryptStr(rs:string):string;
    var
      i:integer;
    begin
      Result:='';
      for i:=Length(rs) downto 1 do
          Result:=Result+chr(ord(rs[i])-1);
    end;//倒序加1加密
    function EncryptStr(rs:string):string;
    var
      i:integer;
    begin
      Result:='';
      for i:=Length(rs) downto 1 do
          Result:=Result+chr(ord(rs[i])+1);
    end;
      

  6.   

    还有一段C#的代码需要大家帮忙的,这段代码涉及到图片的exif信息(数码相片储存的信息)的修改。会的都来看看,谢谢大家的帮忙,分不够的话再加。
    再问一下:为什么我发的帖子的一些字符都不变颜色的(例如var,begin之类的),而你们的会变。public   void   WriteNewDescriptionInImage(string   Filename,string   NewDescription)   
    {   
    Image   Pic;   
    PropertyItem[]   PropertyItems;   
    byte[]   bDescription=new   Byte[NewDescription.Length];   
    int   i;   
    string   FilenameTemp;   
    Encoder   Enc=Encoder.Transformation;   
    EncoderParameters   EncParms=new   EncoderParameters(1);   
    EncoderParameter   EncParm;   
    ImageCodecInfo  CodecInfo=GetEncoderInfo("image/jpeg");
        
    //   copy   description   into   byte   array   
    for   (i=0;i<NewDescription.Length;i++)   bDescription[i]=(byte)NewDescription[i];   
        
    //   load   the   image   to   change   
    Pic=Image.FromFile(Filename);   
    PropertyItems=Pic.PropertyItems;
        
    //   put   the   new   description   into   the   right   property   item   
    PropertyItems=Pic.PropertyItems;     
    PropertyItems[0].Id=0x9286;   //   0x010e   as   specified   in   EXIF   standard   
    PropertyItems[0].Type=2;   
    PropertyItems[0].Len=NewDescription.Length;   
    PropertyItems[0].Value=bDescription;   
    Pic.SetPropertyItem(PropertyItems[0]);   
        
    //   we   cannot   store   in   the   same   image,   so   use   a   temporary   image   instead   
    FilenameTemp=Filename+".temp";   
        
    //   for   lossless   rewriting   must   rotate   the   image   by   90   degrees!   
    EncParm=new   EncoderParameter(Enc,(long)EncoderValue.TransformRotate90);   
    EncParms.Param[0]=EncParm;   
        
    //   now   write   the   rotated   image   with   new   description   
    Pic.Save(FilenameTemp,CodecInfo,EncParms);   
        
    //   for   computers   with   low   memory   and   large   pictures:   release   memory   now   
    Pic.Dispose();   
    Pic=null;   
    GC.Collect();   
        
    //   delete   the   original   file,   will   be   replaced   later   
    System.IO.File.Delete(Filename);     
        
    //   now   must   rotate   back   the   written   picture   
    Pic=Image.FromFile(FilenameTemp);   
    EncParm=new   EncoderParameter(Enc,(long)EncoderValue.TransformRotate270);   
    EncParms.Param[0]=EncParm;   
    Pic.Save(Filename,CodecInfo,EncParms);   
        
    //   release   memory   now   
    Pic.Dispose();   
    Pic=null;   
    GC.Collect();   
        
    //   delete   the   temporary   picture   
    System.IO.File.Delete(FilenameTemp);    
    }   
    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
    int j;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for(j = 0; j < encoders.Length; ++j)
    {
    if(encoders[j].MimeType == mimeType)
    return encoders[j];
    }
    return null;
    }