对一串数字进行加密,要求加密只能后不要出现乱码,只能是数字或字母

youxihaha 2003-09-30 02:43:04
如“3224243424”的一串数字
...全文
231 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
netwizard 2003-09-30
  • 打赏
  • 举报
回复
给你一段别人写的:

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

密钥(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;

47522341 2003-09-30
  • 打赏
  • 举报
回复
function tform1.Encrypt( S: String; Key: Word): String;
var
I: Integer;
j: Integer;
begin
Result := S;
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;
s:=Result;
Result:='';
for i:=1 to length(s) do
begin
j:=Integer(s[i]);
Result:=Result + Char(65+(j div 26))+Char(65+(j mod 26));
end;
end;
---------------------------------------------------
: mengxiang5160(aaa) ( ) 说的这个我以前用过,还算好使,^_^
angle097113 2003-09-30
  • 打赏
  • 举报
回复
如果只是简单的加密的话 那么你让你的数字字符串加上一个数字然后再保存到数据库当中读取的时候在减去这个数字 看看可行吗 但是这是最简单的加密 就是防君子 不防小人
noil0125 2003-09-30
  • 打赏
  • 举报
回复
学习
mengxiang5160 2003-09-30
  • 打赏
  • 举报
回复
函数是:
function tform1.Encrypt( S: String; Key: Word): String;
var
I: Integer;
j: Integer;
begin
Result := S;
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;
s:=Result;
Result:='';
for i:=1 to length(s) do
begin
j:=Integer(s[i]);
Result:=Result + Char(65+(j div 26))+Char(65+(j mod 26));
end;
end;
mengxiang5160 2003-09-30
  • 打赏
  • 举报
回复
给你一个函数,适用于加密的,并且加密后不出现乱码
只是字母和数字
GRANT_Z 2003-09-30
  • 打赏
  • 举报
回复
// Another one
function TransChar(AChar: Char): Integer;
begin
if AChar in ['0'..'9'] then
Result := Ord(AChar) - Ord('0')
else
Result := 10 + Ord(AChar) - Ord('A');
end;

function StrToHex(AStr: string): string;
var
I :Integer;
Tmp: string;
begin
Result := '';
For I := 1 to Length(AStr) do
begin
Result := Result + Format('%2x', [Byte(AStr[I])]);
end;
I := Pos(' ', Result);
While I > 0 do

begin
Result[I] := '0';
I := Pos(' ', Result);
end;
end;

function HexToStr(AStr: string): string;
var
I : Integer;
CharValue: Word;
begin
Result := '';
For I := 1 to Trunc(Length(Astr)/2) do
begin
Result := Result + ' ';
CharValue := TransChar(AStr[2*I-1])*16 + TransChar(AStr[2*I]);
Result[I] := Char(CharValue);
end;
end;
function Encrypt(const S: String; Key: Word): String;
var
I : Integer;
begin
Result := S;
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;
if Result[I] = Chr(0) then
Result[I] := S[I];
end;
Result := StrToHex(Result);
end;

function Decrypt(const S: String; Key: Word): String;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1[I]) xor (Key shr 8)) = Chr(0) then
begin
Result[I] := S1[I];
Key := (byte(Chr(0)) + Key) * C1 + C2; //±£Ö¤KeyµÄÕýÈ·ÐÔ¡¡¡¡
end
else begin
Result[I] := char(byte(S1[I]) xor (Key shr 8));
Key := (byte(S1[I]) + Key) * C1 + C2;
end;
end;
end;




{

Usage:
const
PublicKEY = 20

加密: Password := Encrypt(strPws,PublicKEY);

解密: Password := Decrypt(strPws,PublicKEY);

}

Enjoy
GRANT_Z 2003-09-30
  • 打赏
  • 举报
回复
// just a simple case
function CipherPassword(userpass: string): string;
var
i: integer;
begin
result := '';
for i := 1 to length(userpass) do
begin
if (i mod 2) = 1 then
begin
result := result + char(ord(userpass[i]) xor $5A);
end
else begin
result := result + char(ord(userpass[i]) xor $3B);
end;
end;
end;
youxihaha 2003-09-30
  • 打赏
  • 举报
回复
自己顶

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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