Главная страница


ru.algorithms

 
 - RU.ALGORITHMS ----------------------------------------------------------------
 From : Viktor Karev                         2:5020/400     11 Oct 2001  20:15:33
 To : Vadim Goncharov
 Subject : Re: DES
 -------------------------------------------------------------------------------- 
 
 Приветствия, Vadim Goncharov
 
 > Это такой сложный алгоpитм, что он в плэйнтексте нигде не описан?
 
 Попробую в плэйнтексте.
 2Модератор: пробовал в UUE, гейт не пропускает.
 
 --------------------------------
 unit DES;
 
 (***************************************************************************
 )
 (* Module title : DES implementation
 *)
 (* Written by   : C.Dunkley
 *)
 (***************************************************************************
 )
 
 interface
 
 type
  TDataBlock = array [1..8] of byte;
 
 procedure SetKey(S: string);
 procedure Encode(InBlock: TDataBlock; var OutBlock: TDataBlock);
 procedure Decode(InBlock: TDataBlock; var OutBlock: TDataBlock);
 procedure EncodeText(InS: string; var OutS: string);
 procedure DecodeText(InS: string; var OutS: string);
 
 implementation
 
 type
  Bit       = 0..1;
  BitType   = array [1..64] of Bit;
  PDataBlock = ^TDataBlock;
  Byte8Type = TDataBlock;
  PByte8 = ^Byte8Type;
 
 var
  R,KE,KD : array [1..16] of BitType;
  SBox : array [1..512] of byte;
  Key1 : array [1..64] of byte;
  S    : BitType;
  BTB  : array [0..255] of array [1..8] of Bit;
  Key  : string;
  PKey : integer;
  Len  : integer;
 (***************************************************************************
 )
 
 (***************************************************************************
 )
 (* Used to read in the values of the eight S-Boxes. (from des.dat)
 *)
 (***************************************************************************
 )
 procedure SData(SNum : integer;
         Data : string);
 var
  L1 : integer;
 begin (* 1 SData *)
 for L1 := 1 to 128 do
  SBox[SNum+L1]:=(ord(Data[L1]) shl 2)-191
 end;  (* 1 SData *)
 (***************************************************************************
 )
 
 (***************************************************************************
 )
 (* Initialise ordering arrays. Needs to be called once by application
 *)
 (* program BEFORE any encryption/decryption takes place.
 *)
 (* Needs only to be called ONCE.
 *)
 (***************************************************************************
 )
 procedure InitDes;
 var
  Off,L1 : integer;
  Data   : string;
 begin (* 1 InitDes *)
 Data:='iaYQIA91jbZRJB:2kc[SKC;3ld\Tog_WOG?7nf^VNF>6me]UME=5LD<4';
 for L1 := 1 to 56 do
  Key1[L1]:=ord(Data[L1])-48;
 SData(0,'>4=12?;83:6<59070?74>2=1:6<;953841>8=62;?<973:50?<8249175;3>:06='+
    '?18>6;34972=<05:3=47?28><01:69;50>7;:4=158<6932?=8:13?42;67<05>9');
 SData(128,':09>63?51=<7;428=709346:285><;?1=6498?30;12<5:>71:=069874?>3;52<'
 +
    '7=>3069:1285;<4?=8;56?03472<1:>9:690<;7=?13>52843?06:1=8945;<72>');
 SData(256,'2<417:;6853?=0>9>;2<47=150?:3986421;:=78?9<5630>;8<71>2=6?09:453'
 +
    '<1:?92680=34>75;:?427<9561=>0;389>?528<3704:1=;6432<95?:;>17608=');
 SData(384,'4;2>?08=3<975:61=0;7491:>35<2?8614;=<37>:?6805926;=814:7950?>23<'
 +
     '=2846?;1:93>50<71?=8:374<56;0>927;419<>206:=?35821>74:8=?<90356;');
 Off:=1;
 for L1:=0 to 15 do          (* set up S box binary conversion lookup table
 *)
  begin (* 2 *)
 
  if L1>7          then S[Off+0]:=1 else S[Off+0]:=0;
 
  if odd(L1 div 4) then S[Off+1]:=1 else S[Off+1]:=0;
  if odd(L1 div 2) then S[Off+2]:=1 else S[Off+2]:=0;
  if odd(L1)       then S[Off+3]:=1 else S[Off+3]:=0;
  inc(Off,4)
  end;  (* 2 *)
 for L1:=0 to 255 do                  (* set up bytes to bits lookup tables
 *)
  begin (* 2 *)
 
  if L1>127          then BTB[L1][1]:=1 else BTB[L1][1]:=0;
 
  if odd(L1 div 64)  then BTB[L1][2]:=1 else BTB[L1][2]:=0;
  if odd(L1 div 32)  then BTB[L1][3]:=1 else BTB[L1][3]:=0;
  if odd(L1 div 16)  then BTB[L1][4]:=1 else BTB[L1][4]:=0;
  if odd(L1 div  8)  then BTB[L1][5]:=1 else BTB[L1][5]:=0;
  if odd(L1 div  4)  then BTB[L1][6]:=1 else BTB[L1][6]:=0;
  if odd(L1 div  2)  then BTB[L1][7]:=1 else BTB[L1][7]:=0;
  if odd(L1)         then BTB[L1][8]:=1 else BTB[L1][8]:=0
  end   (* 2 *)
 end;  (* 1 InitDes *)
 (***************************************************************************
 )
 
 Продолжение следует...
 --- ifmail v.2.15dev5
  * Origin: Black Jack House (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 DES   Vadim Goncharov   24 Sep 2001 21:09:27 
 Re: DES   Vinokurov Andrey   25 Sep 2001 13:36:41 
 Re^2: DES   Vadim Goncharov   02 Oct 2001 19:48:01 
 Re: DES   Vinokurov Andrey   03 Oct 2001 19:08:15 
 Re^2: DES   Vadim Goncharov   10 Oct 2001 22:19:24 
 Re: DES   Viktor Karev   11 Oct 2001 20:15:33 
 Re: DES-2   Viktor Karev   11 Oct 2001 20:15:35 
 Re: DES-3   Viktor Karev   11 Oct 2001 20:17:36 
Архивное /ru.algorithms/6577dcd5bc8e.html, оценка 1 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional