首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将字符转换为字符,例如加密

将字符转换为字符,例如加密
EN

Stack Overflow用户
提问于 2014-08-16 05:58:25
回答 1查看 409关注 0票数 0

如何做一个简单的加密解密?

2在项目中制作编辑框和一个按钮,然后用editbox1写一些东西,然后在editbox2中按button1生成这样的一些键。

a:= 1;b:= 2;c:= 3;d:= 4;e:= 5;f:= 6;g:= 7;h:= 8;i:= 9;j:= 0;k:= #;l:= $;m:=%;n:= ~;o:= *;

然后用符号说

a: = 1;意思是:a is 1 if at editbox2

字母(A)是数字1 (B)分段是数字2 (C)分段是数字3简单转换.所以做一个简单的替换密码和解密

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-16 06:31:21

下面是一个简单的替换密码

代码语言:javascript
复制
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;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25337395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档