如何进行简单的加密解密?
2个make编辑框和项目中的按钮,
然后我在editbox1
中写一些内容,然后在button1
中按editbox2
生成一些此类设置中的密钥..
a:= 1; b:= 2; c:= 3; d:= 4; e:= 5; f:= 6; g:= 7; h:= 8; 我:= 9; j:= 0; k:=#; l:= $; m:=%; n:=〜; o:= *;
然后用符号说
a: = 1;
这意味着:a is 1 if at editbox2
字母(A)是数字1(B)项,数字2(C)是数字3的简单转换。所以做一个简单的替换密码和解密
答案 0 :(得分:4)
这是一个简单的替换密码
const
CPlain = 'abcdefghijklmno';
CCrypt = '1234567890#$%~*';
function Transcode( const AStr, ALookupA, ALookupB : string ): string;
var
LIdx, LCharIdx : integer;
begin
// the result has the same length as the input string
SetLength( Result, Length( AStr ) );
// walk through the whole string
for LIdx := 1 to Length( AStr ) do
begin
// find position of char in LookupA
LCharIdx := Pos( AStr[LIdx], ALookupA );
// use the char from LookupB at the previous position
Result[LIdx] := ALookupB[LCharIdx];
end;
end;
function Encrypt( const AStr : string ) : string;
begin
// from plain text to crypt text
Result := Transcode( AStr, CPlain, CCrypt );
end;
function Decrypt( const AStr : string ) : string;
begin
// from crypt text to plain text
Result := Transcode( AStr, CCrypt, CPlain );
end;