[高分求] 如何对字符串的UniCode编码进行加密? 想对一些UniCode字符串进行加密和解密方法,我的思路是比如:我是中国人Abs ,UniCode编码为 6211662F4E2D56FD4EBA004100620073, 然后对其进行加密,解密. 请求高手指教, 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你一个我常用的加密、解密方法:const sBase64: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=!';//------------------------------------------------------------------------------// 按源串,和编码表进行BASE64编码// 顺序为:3个字节折成4个字节,得数不大于64,查表得字符//------------------------------------------------------------------------------function Encode64(sc, table: string): string;var a, b, c: byte; s1, s2, s3, s4: byte; i: Integer;begin result := ''; case length(sc) mod 3 of 1: sc := sc + ' '; //2个空格,凑足3的倍数 2: sc := sc + ' '; //1个空格,凑足3的倍数 end; for i := 0 to (length(sc) div 3 - 1) do begin a := ord(sc[i * 3 + 1]); b := ord(sc[i * 3 + 2]); c := ord(sc[i * 3 + 3]); asm push eax mov ah,a shr ah,2//dfaf mov s1,ah mov ah,a mov al,b and ah,$03 shl ah,4 shr al,4 or ah,al mov s2,ah mov ah,b mov al,c and ah,$0f shl ah,2 shr al,6 or ah,al mov s3,ah mov ah,c and ah,$3f mov s4,ah pop eax end; result := result + table[s1 + 1] + table[s2 + 1] + table[s3 + 1] + table[s4 + 1]; end;end;//------------------------------------------------------------------------------// 按源串,和编码表进行BASE64解码//------------------------------------------------------------------------------function Decode64(sc, table: string): string;var a, b, c: byte; s1, s2, s3, s4: byte; i: Integer;begin result := ''; if Length(sc) mod 4 = 0 then for i := 0 to (Length(sc) div 4 - 1) do begin s1 := AnsiPos(sc[i * 4 + 1], table) - 1; s2 := AnsiPos(sc[i * 4 + 2], table) - 1; s3 := AnsiPos(sc[i * 4 + 3], table) - 1; s4 := AnsiPos(sc[i * 4 + 4], table) - 1; //加密时 值+1 查表,解密时查表值 -1 asm push eax mov ah,s1 mov al,s2 shl ah,2 shr al,4 or ah,al mov a,ah mov ah,s2 mov al,s3 shl ah,4 shr al,2 and al,$0f or ah,al mov b,ah mov ah,s3 mov al,s4 shl ah,6 or ah,al mov c,ah pop eax end; result := result + Chr(a) + Chr(b) + Chr(c); end; result := Trim(result);end;{调用方法:Encode64(S, sBase64) //S为待加密字符串Decode64(S, sBase64) //S这待解密字符串} 在我的blog当中有一个DES加密和解密算法,使用之即可. 如何 查看一个局域网中所有电脑的IP,用户名,MAC地址 ABSolute Datebase 数据库相关 cxgrid 合计 怎么让录入时立即更新合计数 delphi连接局域网内别人机器的SQL SERVER为什么连接不上? 关于DELPHI6的面板。 两个数据库的拷贝数据? 请问如何屏蔽掉Form中的最大化按钮 请能看懂的帮我看看,是什么意思! 看看我的问题吧!button事件的问题! 如何使用TRegistry对注册表读和写!!!!!!!!! 求助,sql查询结果乱码... 你知道我在等你吗
const
sBase64: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=!';//------------------------------------------------------------------------------
// 按源串,和编码表进行BASE64编码
// 顺序为:3个字节折成4个字节,得数不大于64,查表得字符
//------------------------------------------------------------------------------function Encode64(sc, table: string): string;
var a, b, c: byte;
s1, s2, s3, s4: byte;
i: Integer;
begin
result := '';
case length(sc) mod 3 of
1: sc := sc + ' '; //2个空格,凑足3的倍数
2: sc := sc + ' '; //1个空格,凑足3的倍数
end;
for i := 0 to (length(sc) div 3 - 1) do begin
a := ord(sc[i * 3 + 1]);
b := ord(sc[i * 3 + 2]);
c := ord(sc[i * 3 + 3]);
asm
push eax mov ah,a
shr ah,2//dfaf
mov s1,ah mov ah,a
mov al,b
and ah,$03
shl ah,4
shr al,4
or ah,al
mov s2,ah mov ah,b
mov al,c
and ah,$0f
shl ah,2
shr al,6
or ah,al
mov s3,ah mov ah,c
and ah,$3f
mov s4,ah pop eax
end;
result := result + table[s1 + 1] + table[s2 + 1] + table[s3 + 1] + table[s4 + 1];
end;
end;//------------------------------------------------------------------------------
// 按源串,和编码表进行BASE64解码
//------------------------------------------------------------------------------function Decode64(sc, table: string): string;
var a, b, c: byte;
s1, s2, s3, s4: byte;
i: Integer;
begin
result := '';
if Length(sc) mod 4 = 0 then
for i := 0 to (Length(sc) div 4 - 1) do
begin
s1 := AnsiPos(sc[i * 4 + 1], table) - 1;
s2 := AnsiPos(sc[i * 4 + 2], table) - 1;
s3 := AnsiPos(sc[i * 4 + 3], table) - 1;
s4 := AnsiPos(sc[i * 4 + 4], table) - 1; //加密时 值+1 查表,解密时查表值 -1
asm
push eax mov ah,s1
mov al,s2
shl ah,2
shr al,4
or ah,al
mov a,ah mov ah,s2
mov al,s3
shl ah,4
shr al,2
and al,$0f
or ah,al
mov b,ah mov ah,s3
mov al,s4
shl ah,6
or ah,al
mov c,ah pop eax
end;
result := result + Chr(a) + Chr(b) + Chr(c);
end;
result := Trim(result);
end;{
调用方法:
Encode64(S, sBase64) //S为待加密字符串
Decode64(S, sBase64) //S这待解密字符串
}