#!/usr/local/bin/perl

@l=(
	 0, 1, 2, 3, 4, 5, 6, 7,
	 8, 9,10,11,12,13,14,15,
	16,17,18,19,20,21,22,23,
	24,25,26,27,28,29,30,31
	);
@r=(
	32,33,34,35,36,37,38,39,
	40,41,42,43,44,45,46,47,
	48,49,50,51,52,53,54,55,
	56,57,58,59,60,61,62,63
	);

require 'shifts.pl';

sub PERM_OP
	{
	local(*a,*b,*t,$n,$m)=@_;

	@z=&shift(*a,-$n);
	@z=&xor(*b,*z);
	@z=&and(*z,$m);
	@b=&xor(*b,*z);
	@z=&shift(*z,$n);
	@a=&xor(*a,*z);
	}

sub HPERM_OP2
	{
	local(*a,*t,$n,$m)=@_;
	local(@x,@y,$i);

	@z=&shift(*a,16-$n);
	@z=&xor(*a,*z);
	@z=&and(*z,$m);
	@a=&xor(*a,*z);
	@z=&shift(*z,$n-16);
	@a=&xor(*a,*z);
	}

sub HPERM_OP
        {
        local(*a,*t,$n,$m)=@_;
        local(@x,@y,$i);

        for ($i=0; $i<16; $i++)
                {
                $x[$i]=$a[$i];
                $y[$i]=$a[16+$i];
                }
        @z=&shift(*x,-$n);
        @z=&xor(*y,*z);
        @z=&and(*z,$m);
        @y=&xor(*y,*z);
        @z=&shift(*z,$n);
        @x=&xor(*x,*z);
        for ($i=0; $i<16; $i++)
                {
                $a[$i]=$x[$i];
                $a[16+$i]=$y[$i];
                }
        }

@L=@l;
@R=@r;
#&PERM_OP(*R,*L,*T,4,0x0f0f0f0f);
#&HPERM_OP2(*L,*T,-2, 0xcccc0000);
#&HPERM_OP2(*L,*T,-1, 0xaaaa0000);
#&HPERM_OP2(*L,*T,8,  0x00ff0000);
#&HPERM_OP2(*L,*T,-1, 0xaaaa0000);
#&HPERM_OP2(*R,*T,-8, 0xff000000);
#&HPERM_OP2(*R,*T,8,  0x00ff0000);
#&HPERM_OP2(*R,*T,2,  0x33330000);
#
#@A=&and(*R,0x00aa00aa);
#@A=&shift(*A,7);
#@B=&and(*R,0x55005500);
#@B=&shift(*B,-7);
#@C=&and(*R,0xaa55aa55);
#@R=&or(*A,*B);
#@R=&or(*R,*C);
#@T=&and(*L,0xf0000000);
#@T=&shift(*T,-4);
#@R=&shift(*R,-8);
#@R=&or(*R,*T);
#@L=&and(*L,0x0fffffff);
#	&printit(@L);
#	&printit(@R);

&PERM_OP(*R,*L,*T,4,0x0f0f0f0f);
&HPERM_OP2(*L,*T,-2,0xcccc0000);
&HPERM_OP2(*R,*T,-2,0xcccc0000);
&PERM_OP(*R,*L,*T,1,0x55555555);
&PERM_OP(*L,*R,*T,8,0x00ff00ff);
&PERM_OP(*R,*L,*T,1,0x55555555);

@A=&and(*R,0x000000ff);
@A=&shift(*A,16);
@B=&and(*R,0x0000ff00);
@C=&and(*R,0x00ff0000);
@C=&shift(*C,-16);
@D=&and(*L,0xf0000000);
@D=&shift(*D,-4);
@A=&or(*A,*B);
@B=&or(*D,*C);
@R=&or(*A,*B);
@L=&and(*L,0x0fffffff);

	&printit(@L);
	&printit(@R);

