求一文本加密算法.

seav 2005-06-28 09:20:22
1.要求不要太简单,不易破解.
2.要可逆的.用一个Key加密,也要用这个Key解密.
...全文
252 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhzqf1980 2005-07-01
  • 打赏
  • 举报
回复
function tForm1.Decrypt(const s:string):string; //key=1时为加密,0为解密
var
I:Integer;
begin
Result:='';
for i:=1 to length(s) do
result := result+chr(ord(s[i]) xor i xor 69);
result := result + char(69);
end;
function tForm1.Decrypt1(const s:string):string; //key=1时为加密,0为解密
var
I:Integer;
begin
Result:='';
for i:=1 to length(s) - 1 do
result := result+chr(ord(s[i]) xor i xor 69);
end;
zklove 2005-06-30
  • 打赏
  • 举报
回复
const strKey = 'abcdefgh';


Function EncrypKey (Src:String; Key:String):string;
var
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc :Integer;
TmpSrcAsc :Integer;
Range :Integer;
begin
if Src = '' then
begin
result := '';
exit;
end;

KeyLen:=Length(Key);
if KeyLen = 0 then key:='Think Space';
KeyPos:=0;
SrcPos:=0;
SrcAsc:=0;
Range:=256;

Randomize;
offset:=Random(Range);
dest:=format('%1.2x',[offset]);
for SrcPos := 1 to Length(Src) do
begin
SrcAsc:=(Ord(Src[SrcPos]) + offset) MOD 255;
if KeyPos < KeyLen then KeyPos:= KeyPos + 1 else KeyPos:=1;
SrcAsc:= SrcAsc xor Ord(Key[KeyPos]);
dest:=dest + format('%1.2x',[SrcAsc]);
offset:=SrcAsc;
end;
Result:=Dest;
end;


Function UncrypKey (Src:String; Key:String):string;
var
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc :Integer;
TmpSrcAsc :Integer;
begin
if Src = '' then
begin
result := '';
exit;
end;

KeyLen:=Length(Key);
if KeyLen = 0 then key:='Think Space';
KeyPos:=0;
SrcPos:=0;
SrcAsc:=0;
offset:=StrToInt('$'+ copy(src,1,2));
SrcPos:=3;
repeat
SrcAsc:=StrToInt('$'+ copy(src,SrcPos,2));
if KeyPos < KeyLen Then KeyPos := KeyPos + 1 else KeyPos := 1;
TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);
if TmpSrcAsc <= offset then
TmpSrcAsc := 255 + TmpSrcAsc - offset
else
TmpSrcAsc := TmpSrcAsc - offset;
if TmpSrcAsc = 0 then TmpSrcAsc :=255;
dest := dest + chr(TmpSrcAsc);
offset:=srcAsc;
SrcPos:=SrcPos + 2;
until SrcPos >= Length(Src);
Result:=Dest;
end;
特点是所有加密的字符都是可见字符,不过加密程度不高
gobiz 2005-06-29
  • 打赏
  • 举报
回复
用最强悍的,AES+自定义的CRC校验位,我就不信有人可以解的出来。
FlyHope2005 2005-06-29
  • 打赏
  • 举报
回复
用des:
http://blog.csdn.net/flyhope2005/archive/2005/01/05/240311.aspx
fongming 2005-06-29
  • 打赏
  • 举报
回复
楼上的有64个字母啊
seav 2005-06-29
  • 打赏
  • 举报
回复
http://blog.csdn.net/flyhope2005/archive/2005/01/05/240311.aspx
此算法,主要修改哪里?
xthmpro_cn 2005-06-29
  • 打赏
  • 举报
回复
来自:葵花宝典
program Crypt;
uses WinCRT;
const
C1 = 52845;
C2 = 22719;
function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result[0] := S[0];
for I := 1 to Length(S) do begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
end;
end;

function Decrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result[0] := S[0];
for I := 1 to Length(S) do begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(S[I]) + Key) * C1 + C2;
end;
end;

var
S: string;
begin
Write('>');
ReadLn(S);
S := Encrypt(S,12345);
WriteLn(S);
S := Decrypt(S,12345);
WriteLn(S);
end.
//////////////////////////////////////////////////////
unit Unit2;

interface

Const Allchar: string = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789';

procedure Encrypt( var ss: string );

implementation

procedure Encrypt( var ss: string );
var l, lac, // string length
sp, // ss char pointer
cp: integer; // allchar pointer
begin
l := Length(ss);
lac := Length( Allchar );
sp := 1;
while sp <= l do begin
cp := 1;
while (allchar[cp] <> ss[sp]) and ( cp <= lac ) do inc( cp );
{ match char and find the encrypted counterpart in the reverse
order in position }
if cp > lac then ss[sp]:= '*'
{ Mark illegal char - use only char not in allchar }
else begin
{ Un-remark next line will further enhance security...
such that same character will appear as
different after encrypt }

// cp := (( cp + sp*2 ) mod lac) + 1;

ss[sp] := allchar[ lac - cp + 1 ]; //first char result in the last
end;
inc(sp);
end;
end;


end.

{ Specail about this procedure:

1. Same procedure to encrypt and decrypt.
( less code to maintain. )
2. Every Allchar set produce a different encryption.
{ a set of 62 char produce 3.147E85 combinations )
3. Full control over character set of encrypted string.
( good for 7-bit fields, barcoding, passwords, magstripe and filenames etc )
4. One table lookup. ( easy to ensure no duplication possible
for every possible allchar. So as a need to remove/add chars )
5. Automatic marking of illegal characters.
( simplified coding needs. )



--------------------------------------------------------------------------------


以下介绍的加密算法强度不高,我编写它是因为我需要既保持文本是由可打印字符组成的,同时又无法直接看到,也许一个孩子花上十分钟就可以破解这个算法......也许吧,这我不清楚,而且也不关心,因为我只要它能达到我的目的就行。



密钥(Key)的长度可以设置为任意长度。在这个函数中,将每个字符的低四位和密钥中字符的低四位进行XOR运算,这样加密后的字符仍然是7位的字符同时也是可打印的。





{注意 :- Key如果为空,则使用缺省密钥}

function DenCrypt(Str : string; Key : string): string;

var

X, Y : Integer;

A : Byte;

begin

if Key = '' then

Key := 'd1duOsy3n6qrPr2eF9u';

Y := 1;

for X := 1 to length(Str) do begin

A := (ord(Str[X]) and $0f) xor (ord(Key[Y]) and $0f);

Str[X] := char((ord(Str[X]) and $f0) + A);

inc(Y);

if Y > length(Key) then

Y := 1;

end;

Result := Str;

end;



由于函数使用的是简单的XOR运算,因此你可以再次以相同的密钥调用此函数就可以解密字符串。


hellolongbin 2005-06-29
  • 打赏
  • 举报
回复
不要太简单?那就去专门的网站找算法好了
僵哥 2005-06-28
  • 打赏
  • 举报
回复
就是将六十四字母的顺序乱排一气。
seav 2005-06-28
  • 打赏
  • 举报
回复
base64,我也知道,不过我不知道怎样去修改其加密过程,如果不改的话,这个就好像没有加密一样,因为知道的人太多了.可以提供源码,并说明修改方法吗
僵哥 2005-06-28
  • 打赏
  • 举报
回复
呵呵,Base64

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧