【问题标题】:convert char to char such as encryption将 char 转换为 char 等加密
【发布时间】:2014-08-16 05:58:25
【问题描述】:

如何进行简单的加密解密?
项目中2个make编辑框和一个按钮, 然后我在editbox1 中写一些东西,然后在editbox2 中按button1 在这样的设置中生成一些键..

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

然后用符号 say
a: = 1; 表示:a is 1 if at editbox2

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

【问题讨论】:

  • 这与 TEdit 和 TButton 有什么关系?这是一个简单的字符串转换
  • 您正在寻找substitution cipher
  • 好的,那么问题出在哪里?到目前为止你尝试了什么(代码),你在哪里卡住了? (请不要将代码添加为注释,放在问题中)
  • 因为你问了一个delphi相关的问题,我们都期待某种delphi代码......
  • 顺便说一句,这不是“字母到数字”它只是“字符到字符”

标签: delphi delphi-7 delphi-2010


【解决方案1】:

这是一个简单的替换密码

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;

【讨论】:

    猜你喜欢
    • 2010-10-12
    • 2021-04-29
    • 2013-10-18
    • 2012-01-15
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 2012-07-01
    相关资源
    最近更新 更多