int mir_decode(unsigned char *binary, char *text, int size)
{
unsigned char *step;
int loop, bits;
char idx; step = binary;
bits = 2; for (loop = 0; loop < size; ++loop)
{
idx = *text++ - 0x3c;
if (idx < 0 || idx >= 64)
{
return -1;
}
if (bits != 2)
{
step[-1] |= idx >> (8 - bits);
}
if (bits != 8)
{
*step++ = idx << bits;
bits += 2;
}
else
{
bits = 2;
}
} if (size & 3)
{
--step;
} return step - binary;
}int mir_encode(char *text, unsigned char *binary, int size)
{
char *step;
unsigned char b, idx;
int loop, bits; step = text;
b = 0;
bits = 6; for (loop = 0; loop < size; ++loop)
{
idx = *binary++;
*step++ = ((idx >> (8 - bits)) | b) + 0x3c;
b = (idx << (bits - 2)) & 0x3f;
bits -= 2;
if (!bits)
{
*step++ = b + 0x3c;
b = 0;
bits = 6;
}
}
if (bits != 6)
{
*step++ = b + 0x3c;
} return step - text;
}
{
unsigned char *step;
int loop, bits;
char idx; step = binary;
bits = 2; for (loop = 0; loop < size; ++loop)
{
idx = *text++ - 0x3c;
if (idx < 0 || idx >= 64)
{
return -1;
}
if (bits != 2)
{
step[-1] |= idx >> (8 - bits);
}
if (bits != 8)
{
*step++ = idx << bits;
bits += 2;
}
else
{
bits = 2;
}
} if (size & 3)
{
--step;
} return step - binary;
}int mir_encode(char *text, unsigned char *binary, int size)
{
char *step;
unsigned char b, idx;
int loop, bits; step = text;
b = 0;
bits = 6; for (loop = 0; loop < size; ++loop)
{
idx = *binary++;
*step++ = ((idx >> (8 - bits)) | b) + 0x3c;
b = (idx << (bits - 2)) & 0x3f;
bits -= 2;
if (!bits)
{
*step++ = b + 0x3c;
b = 0;
bits = 6;
}
}
if (bits != 6)
{
*step++ = b + 0x3c;
} return step - text;
}
解决方案 »
- delphi 2010 或 ex 下 com 口 开发
- Win98的共享borlndmm.dll错误。
- 急求AUTOCAD数据读取,以及AUTOCAD的图形比较
- 搜索了CSDN的资料宝库,还是不能解决的高难问题-----有关快捷方式和ShellExecuteEx!!
- delphi的脾气太坏了,我还没掌握他的习性,了解他习性的进来看看,散分
- 关于OnTimer事件
- ADOQuery控件的SQL语句有日期型的参数,如何符值??????有分
- 在quickrep中统计本月纪录的合计,然后打印。
- delphi 跟bcb谁强?
- 菜人问题:有关数据库表的记录删除。
- 高分。关于lookupcombox的!
- 请问哪里有李维的《inside VCL 架构剖析》电子版的下载地址啊?
function mir_decode(binary,text:PChar; size:integer):integer;
var
// unsigned char *step;
step:PChar;
// int loop, bits;
loop, bits:integer;
// char idx;
idx:Byte;
begin step := binary;
bits := 2; // for (loop = 0; loop < size; ++loop)
for loop:=0 to size-1 do
begin
//idx = *text++ - 0x3c;
idx:=byte(text^)-$3c;
inc(text);
if (idx < 0) or( idx >= 64) then
begin
result:=-1;
exit;
end;
if (bits <> 2) then
begin
// step[-1] |= idx >> (8 - bits);
step[-1]:= Chr(Byte(step[-1]) or (idx shr (8 - bits)));
end;
if (bits <> 8) then
begin
{
*step++ = idx << bits;
bits += 2;
}
step^:=Chr(idx shl bits);
inc(step);
inc(bits,2);
end else
bits := 2; end; if ((size and 3)>0) then
dec(step); result:=step - binary;
end;//int mir_encode(char *text, unsigned char *binary, int size)
function mir_encode(text,binary:PChar;size:integer):integer;
var
// unsigned char *step;
step:PChar;
// int loop, bits;
loop, bits:integer;
// unsigned char b, idx;
b,idx:Byte;
begin
step := text;
b := 0;
bits:= 6; // for (loop = 0; loop < size; ++loop)
for loop:=0 to size-1 do
begin
// idx = *binary++;
idx:=Byte(binary^);
inc(binary);
// *step++ = ((idx >> (8 - bits)) | b) + 0x3c;
step^:=Chr(((idx shr (8 - bits)) or b) + $3c) ;
inc(step);
// b = (idx << (bits - 2)) & 0x3f;
b:=(idx shl (bits - 2)) and $3f;
// bits -= 2;
dec(bits,2);
if (bits=0) then
begin
{
*step++ = b + 0x3c;
b = 0;
bits = 6;
}
step^:=Chr(b+$3c);
inc(step);
b:=0;
bits:=6;
end;
end;
if (bits <> 6) then
begin
step^:=Chr(b+$3c);
inc(step);
end; result:=step - text;
end;
var
step:byte;
loop,bits:integer;
idx:byte;
begin
step:=binary;
bits:=2;
for loop :=1 to size do
begin
idx:=INC(text)-$3c;
if (idx<0) or idx>=64 then
begin
result:=-1;
end; if bits<>2 then
begin
step[-1]:=(step[-1]) or (idx shr (8-bits));
end; if bits<>8 then
begin
step:=idx shl bits;
inc(step);
inc(bits,2);
end
else
bits:=2;
end;
end;
if (size and 3)=1 then
begin
DEC(step);
end; result:=step-binary;
end;function mir_encode(text,binary:byte,size:integer):integer;
var
step,b,idx:byte;
loop,bits:integer;
begin
step:=text;
b:=0;
bits:=6;
for loop :=1 to size do
begin
idx:=INC(binary);
step:=((idx shr (8-bits)) or b) + $3c;
inc(step);
b=(idx shl (bits-2)) and $3f;
bits:=bits-2;
if bits=0 then
begin
INC(step):=b+$3c;
end;
result:=step-text;
end;
end;随手翻的,肯定有错,有什么不清楚的,跟贴