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;
}
{
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;
}
解决方案 »
- 利用dbgrideh的SelectedRows和GotoBookmark批量形成字符串
- dll编程Access violation at address的问题
- 求助下"在Edit1中输入汉字的同时在Edit2中显示每个汉字的声母字符"
- [急]DBGridEh 显示空白区域
- 简单的问题(刚学Delphi,原来是用CB的,菜问题,不要笑)
- TreeNode颜色控制
- agent 中如何定义右键菜单触发事件?
- 学delphi北京哪里比较好?
- 菜鸟问题
- 为何Fastnet的FTP控件不能传大文件????
- 当前时间问题
- 调用OnGetText事件总是出错?[Error] pubunit.pas(658): Incompatible types: 'method pointer and regular procedure'
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;
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;帮你改了下,但运行结果好像是少翻译了最后一位
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;可以用了(包括汉字和其它字符),呵呵
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;
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;
再问一下:为什么我发的帖子的一些字符都不变颜色的(例如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;
}