有两个字符串,假设为A,B,我想将A每次取两位然后与B的前两位进行异或,然后将结果连接成一个字符串,请问该如何编写?请给出完整的代码,谢谢~还有就是如何取固定长度的字符串,比如一个字符串有25位,我想取它的前10位如何取?
解决方案 »
- 怎样提取出文章中的关键词?用delphi实现
- 我用的是fastreport3.0,在设计精确打印的时候发现,fastreport3.0里的尺寸和现实中的不一样,我该怎么做?
- 找了很久很久的一个新手学习Midas,WebService,Soap的问题,别见笑
- Dpr结束报EAccessViolation错误和取标题栏高度的问题.
- 运行时候老出错,高手帮我看一下怎么回事啊,谢谢大家!
- 如何用ADO的方法联接一个EXCEL表?
- 我加载一接口商提供的DLL文件,放在自己新建的一个文件夹就会提示文件不完整,放在system32下就可以?
- 请问编程高手:安装程序中 ini文件是如何写成的,注册又是如何写成的??? 谢谢那位热心朋友耐心给我讲解好么?
- 请回答mss2的问题啊,我还是不会啊,高分请叫急要用啊,请看正文说明:急请叫高手帮助:我想在DELPHI用SQL语句汇总要在指定日期内汇总某一字段
- 带参数的存储过程如何写
- 为何点主窗体(全屏显示的)时,其它已经show出来的窗体被挡住?
- ODAC的两个问题:连接ORACLE数据库超时,该怎么解决?
a,b,c:string;
count:integer;
i:integer;
temp:string;
begin
a:='aabbaaccdd';
b:='aabbcc';
b:=copy(b,1,2);
count:=length( a ) div 2;
i:=1;
while count<>0 do
begin
temp:=copy(a,i,2);
if temp<>b then
c:=c+temp;
inc(i,2);
inc(count,-1);
end;
showmessage( c );end;
Copy(A,1,10);异或后基本就是乱码了,呵呵
const B : String = '12';
var
A,C:String;
Buf:array[0..1] of byte;
I:integer;
begin
A:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
C:='';
I:=1;
While I< Length(A) do begin
Buf[0]:=Ord(A[I]);
BUf[1]:=Ord(A[I+1]);
Inc(I,2);
C:=C+Char(Buf[0] xor Ord(B[1])) + Char(Buf[0] xor Ord(B[2]));
end;
showmessage(c); //C为结果
end;
var
iKey : Integer;
iLoop: Integer;
begin
SetLength(Result, Length(sString));
iKey := 1;
for iLoop := 1 to Length(sString) do
begin
Result[iLoop] := chr(ord(sString[iLoop]) xor ord(sKey[iKey]));
inc(iKey);
if iKey > Length(sKey) then iKey := 1;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(EncryptString('ABCDEFGHIJKLMN', '12'));
end;
var
Map: array['0'..'F'] of byte =
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, $A, $B, $C, $D, $E, $F);
Map2: array[0..$F] of char =
('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F');//两个Map必须是全局变量procedure TForm1.Button2Click(Sender: TObject);
var
S1, S2, S3: string;
I: integer;
begin
SetLength(S3, Length(S1));//s1 s2必须假定长度相等。
for I := 1 to Length(S1) do
S3[I] := Map2[Map[S1[I]] xor Map[S2[I]]];
//结果在S3中
end;
固定字符4B4130与6F65进行运算,该怎么写?每次取4B4130两位然后与6F65的前两位进行异或,然后将结果连接成一个字符串谢谢楼上的各位兄弟!
是这个概念
4 xor 6
B xor F
还是这个
$4B xor $6F
$41 xor $65
说清楚点
取4B和6F异或,得到24,41与6F异或得2E,30与6F异或得5F,然后连接起来得到242E5F
var
iKey : Integer;
iLoop: Integer;
AByte: Byte;
begin
Result := '';
iKey := 1;
for iLoop := 1 to Length(sString) div 2 do
begin
AByte := StrToInt('$' + copy(sString, iLoop * 2 - 1, 2));
AByte := AByte xor StrToInt('$' + copy(sKey, iKey * 2 - 1, 2));
Result := Result + IntToHex(AByte, 2);
inc(iKey);
if iKey > Length(sKey) div 2 then iKey := 1;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(XorHexString('4B4130', '6F65'));
end;
var
Map: array['0'..'F'] of byte =
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, $A, $B, $C, $D, $E, $F);
Map2: array[0..$F] of char =
('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F');//两个Map必须是全局变量procedure TForm1.Button2Click(Sender: TObject);
var
S1, S2, S3: string;
I: integer;
begin
SetLength(S3, Length(S1));
for I := 1 to Length(S1) do
S3[I] := Map2[Map[S1[I]] xor Map[S2[((I-1) mod 4)+1]]];
//结果在S3中
end;