import cyrus-sasl-2.1.23
[cyrus-sasl.git] / mac / libdes / src / doPC1
1 #!/usr/local/bin/perl\r\r@l=(\r     0, 1, 2, 3, 4, 5, 6, 7,\r        8, 9,10,11,12,13,14,15,\r       16,17,18,19,20,21,22,23,\r       24,25,26,27,28,29,30,31\r        );\r@r=(\r        32,33,34,35,36,37,38,39,\r       40,41,42,43,44,45,46,47,\r       48,49,50,51,52,53,54,55,\r       56,57,58,59,60,61,62,63\r        );\r\rrequire 'shifts.pl';\r\rsub PERM_OP\r  {\r      local(*a,*b,*t,$n,$m)=@_;\r\r     @z=&shift(*a,-$n);\r     @z=&xor(*b,*z);\r        @z=&and(*z,$m);\r        @b=&xor(*b,*z);\r        @z=&shift(*z,$n);\r      @a=&xor(*a,*z);\r        }\r\rsub HPERM_OP2\r       {\r      local(*a,*t,$n,$m)=@_;\r local(@x,@y,$i);\r\r      @z=&shift(*a,16-$n);\r   @z=&xor(*a,*z);\r        @z=&and(*z,$m);\r        @a=&xor(*a,*z);\r        @z=&shift(*z,$n-16);\r   @a=&xor(*a,*z);\r        }\r\rsub HPERM_OP\r        {\r        local(*a,*t,$n,$m)=@_;\r        local(@x,@y,$i);\r\r        for ($i=0; $i<16; $i++)\r                {\r                $x[$i]=$a[$i];\r                $y[$i]=$a[16+$i];\r                }\r        @z=&shift(*x,-$n);\r        @z=&xor(*y,*z);\r        @z=&and(*z,$m);\r        @y=&xor(*y,*z);\r        @z=&shift(*z,$n);\r        @x=&xor(*x,*z);\r        for ($i=0; $i<16; $i++)\r                {\r                $a[$i]=$x[$i];\r                $a[16+$i]=$y[$i];\r                }\r        }\r\r@L=@l;\r@R=@r;\r\r    print "---\n"; &printit(@R);\r&PERM_OP(*R,*L,*T,4,0x0f0f0f0f);\r  print "---\n"; &printit(@R);\r&HPERM_OP2(*L,*T,-2,0xcccc0000);\r&HPERM_OP2(*R,*T,-2,0xcccc0000);\r print "---\n"; &printit(@R);\r&PERM_OP(*R,*L,*T,1,0x55555555);\r  print "---\n"; &printit(@R);\r&PERM_OP(*L,*R,*T,8,0x00ff00ff);\r  print "---\n"; &printit(@R);\r&PERM_OP(*R,*L,*T,1,0x55555555);\r  print "---\n"; &printit(@R);\r#  &printit(@L);\r  &printit(@R);\rprint <<"EOF";\r==============================\r63  55  47  39  31  23  15   7  \r62  54  46  38  30  22  14   6  \r61  53  45  37  29  21  13   5  \r60  52  44  36  --  --  --  --  \r\r57  49  41  33  25  17   9   1  \r58  50  42  34  26  18  10   2  \r59  51  43  35  27  19  11   3  \r28  20  12   4  --  --  --  --  \rEOF\rexit(1);\r@A=&and(*R,0x000000ff);\r@A=&shift(*A,16);\r@B=&and(*R,0x0000ff00);\r@C=&and(*R,0x00ff0000);\r@C=&shift(*C,-16);\r@D=&and(*L,0xf0000000);\r@D=&shift(*D,-4);\r@A=&or(*A,*B);\r@B=&or(*D,*C);\r@R=&or(*A,*B);\r@L=&and(*L,0x0fffffff);\r\r &printit(@L);\r  &printit(@R);\r\r