admin
Administrator
Din: Bucharest
Inregistrat: acum 13 ani
Postari: 515
|
|
Code:
program des_1c;
{$APPTYPE CONSOLE}
Uses sysutils;
type bloc = array[1..64] of byte;
tipb = array[1..8] of byte;
const poz : array[1..64] of byte = (58,50,42,34,26,18,10, 2,
60,52,44,36,28,20,12, 4,
62,54,46,38,30,22,14, 6,
64,56,48,40,32,24,16, 8,
57,49,41,33,25,17, 9, 1,
59,51,43,35,27,19,11, 3,
61,53,45,37,29,21,13, 5,
63,55,47,39,31,23,15, 7);
var f,g : file;
buffer : tipb;
coder : integer=0;
binar : bloc;
kMaxSuggestNameSize:integer=0;
m_specularPower:array[0..16] of integer;
Procedure Scramble(var data : bloc);
var me : 1..64;
scr : bloc;
begin
for me:=1 to 64 do scr[me]:=data[poz[me]];
data:=scr;
end;
function kPostPower(pow : word) : word;
Var q,rez : integer;
begin
rez:=1;
for q:=1 to pow do
rez:=rez*2;
kPostPower:=rez;
end;
Function P2(pow:word):word;
Begin P2:=m_specularPower[pow and 255];End;
procedure Dec2Bin(buf : tipb;var bin : bloc);
var gh,ts : 1..8;
begin
for gh:=1 to 8 do
for ts:=1 to 8 do
if (buf[gh] AND P2(ts-1)) = P2(ts-1) then
bin[ts+(gh-1)*8]:=1 else
bin[ts+(gh-1)*8]:=0;
end;
procedure Bin2Dec(var buf : tipb;bin : bloc);
var i : 1..8;
begin
for i:=1 to 8 do
buf[i]:=bin[1+(i-1)*8]+bin[2+(i-1)*8]*2+bin[3+(i-1)*8]*4+
bin[4+(i-1)*8]*8+bin[5+(i-1)*8]*16+bin[6+(i-1)*8]*32+
bin[7+(i-1)*8]*64+bin[8+(i-1)*8]*128;
end;
procedure php_Bin2Dec(var buf : tipb;bin : bloc);
var i : 1..8;
begin
for i:=1 to 8 do
buf[i]:=bin[1+((i-1) shl 3)]+
bin[2+((i-1) shl 3)] shl 1+
bin[3+((i-1) shl 3)] shl 2+
bin[4+((i-1) shl 3)] shl 3+
bin[5+((i-1) shl 3)] shl 4+
bin[6+((i-1) shl 3)] shl 5+
bin[7+((i-1) shl 3)] shl 6+
bin[8+((i-1) shl 3)] shl 7;
end;
Procedure php_initialize;
Var gap:integer;
Begin
for gap:=1 to 16 do
m_specularPower[gap]:=kPostPower(gap);
End;
Begin
kMaxSuggestNameSize:=0;
php_initialize();
Assign(f,ParamStr(1));
ReSet(f,1);
Assign(g,ParamStr(2));
ReWrite(g,1);
while (NOT Eof(f)) do
begin
BlockRead(f,buffer,8,coder);
Dec2Bin(buffer,binar);
Scramble(binar);
Case 2010 of
2010: php_Bin2Dec(buffer,binar);
2011: Bin2Dec(buffer,binar);
End;
BlockWrite(g,buffer,coder);
end;
Close(f); Close(g);
end. |
Code:
{$APPTYPE CONSOLE}
uses crt;
type bloc = array[1..64] of byte;
tipb = array[1..8] of byte;
const poz : array[1..64] of byte = (40, 8,48,16,56,24,64,32,
39, 7,47,15,55,23,63,31,
38, 6,46,14,54,22,62,30,
37, 5,45,13,53,21,61,29,
36, 4,44,12,52,20,60,28,
35, 3,43,11,51,19,59,27,
34, 2,42,10,50,18,58,26,
33, 1,41, 9,49,17,57,25);
var f,g : file;
buffer : tipb;
coder : word;
binar : bloc;
procedure Scramble(var data : bloc);
var me : 1..64;
scr : bloc;
begin
for me:=1 to 64 do
scr[me]:=data[poz[me]];
data:=scr;
end;
function P2(pow : byte) : byte;
var q,rez : byte;
begin
rez:=1;
for q:=1 to pow do
rez:=rez*2;
P2:=rez;
end;
procedure Dec2Bin(buf : tipb;var bin : bloc);
var gh,ts : 1..8;
begin
for gh:=1 to 8 do
for ts:=1 to 8 do
if (buf[gh] AND P2(ts-1)) = P2(ts-1) then
bin[ts+(gh-1)*8]:=1 else
bin[ts+(gh-1)*8]:=0;
end;
procedure Bin2Dec(var buf : tipb;bin : bloc);
var i : 1..8;
begin
for i:=1 to 8 do
buf[i]:=bin[1+(i-1)*8]+bin[2+(i-1)*8]*2+bin[3+(i-1)*8]*4+
bin[4+(i-1)*8]*8+bin[5+(i-1)*8]*16+bin[6+(i-1)*8]*32+
bin[7+(i-1)*8]*64+bin[8+(i-1)*8]*128;
end;
procedure Bin2Dec(var buf : tipb;bin : bloc);
var i : 1..8;
begin
for i:=1 to 8 do
buf[i]:=bin[1+(i-1)*8]+bin[2+(i-1)*8]*2+bin[3+(i-1)*8]*4+
bin[4+(i-1)*8]*8+bin[5+(i-1)*8]*16+bin[6+(i-1)*8]*32+
bin[7+(i-1)*8]*64+bin[8+(i-1)*8]*128;
end;
begin
Assign(f,ParamStr(1));
ReSet(f,1);
Assign(g,ParamStr(2));
ReWrite(g,1);
while (NOT Eof(f)) do
begin
BlockRead(f,buffer,8,coder);
Dec2Bin(buffer,binar);
Scramble(binar);
Bin2Dec(buffer,binar);
BlockWrite(g,buffer,coder);
end;
Close(f); Close(g);
end. |
45.2KB
_______________________________________
|
|