Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I wrote this PHP script trying to implement DES algorithm. I'm running it on terminal, not browser, with

php des.php AAAAAAAA AAAAAAAA

Here the script

<?php

$SANDBOX_1=array(
        array(14,4,13,1,2,15,11,8,3,10,6,12,5,9,0,7),
        array(0,15,7,4,14,2,13,1,10,6,12,11,9,5,3,8),
        array(4,1,14,8,13,6,2,11,15,12,9,7,3,10,5,0),
        array(15,12,8,2,4,9,1,7,5,11,3,14,10,0,6,1),
        );
$SANDBOX_2=array(
        array(15,1,8,14,6,11,3,4,9,7,2,13,12,0,5,10),
        array(3,13,4,7,15,2,8,14,12,0,1,10,6,9,11,5),
        array(0,14,7,11,10,4,13,1,5,8,12,6,9,3,2,15),
        array(13,8,10,1,3,15,4,2,11,6,7,12,0,5,14,9),
        );
$SANDBOX_3=array(
        array(10,0,9,14,6,3,15,5,1,13,12,7,11,4,2,8),
        array(13,7,0,9,3,4,6,10,2,8,5,14,12,11,15,1),
        array(13,6,4,9,8,15,3,0,11,1,2,12,5,10,14,7),
        array(1,10,13,0,6,9,8,7,4,15,14,3,11,5,2,12),
        );
$SANDBOX_4=array(
        array(7,13,14,3,0,6,9,10,1,2,8,5,11,12,4,15),
        array(13,8,11,5,6,15,0,3,4,7,2,12,1,10,14,9),
        array(10,6,9,0,12,11,7,13,15,1,3,14,5,2,8,4),
        array(3,15,0,6,10,1,13,8,9,4,5,11,12,7,2,14),
        );
$SANDBOX_5=array(
        array(2,12,4,1,7,10,11,6,8,5,3,15,13,0,14,9),
        array(14,11,2,12,4,7,13,1,5,0,15,10,3,9,8,6),
        array(4,2,1,11,10,13,7,8,15,9,12,5,6,3,0,14),
        array(11,8,12,7,1,14,2,13,6,15,0,9,10,4,5,3),
        );
$SANDBOX_6=array(
        array(12,1,10,15,9,2,6,8,0,13,3,4,14,7,5,11),
        array(10,15,4,2,7,12,9,5,6,1,13,14,0,11,3,8),
        array(9,14,15,5,2,8,12,3,7,0,4,10,1,13,11,6),
        array(4,3,2,12,9,5,15,10,11,14,1,7,6,0,8,13),
        );
$SANDBOX_7=array(
        array(4,11,2,14,15,0,8,13,3,12,9,7,5,10,6,1),
        array(13,0,11,7,4,9,1,10,14,3,5,12,2,15,8,6),
        array(1,4,11,13,12,3,7,14,10,15,6,8,0,5,9,2),
        array(6,11,13,8,1,4,10,7,9,5,0,15,14,2,3,12),
        );
$SANDBOX_8=array(
        array(13,2,8,4,6,15,11,1,10,9,3,14,5,0,12,7),
        array(1,15,13,8,10,3,7,4,12,5,6,11,0,14,9,2),
        array(7,11,4,1,9,12,14,2,0,6,10,13,15,3,5,8),
        array(2,1,14,7,4,10,8,13,15,12,9,0,3,5,6,11),
        );
$replace="";
$msg=$argv[1]; 
$key=$argv[2];
echo"***************************************************************************\n";
echo"|                    DES ENCODING ALGORITHM                               |\n";
echo"|                    sat 29 aug 2015                                      |\n";
echo"|                                                                 |\n";
echo"***************************************************************************\n";
/*if ( strlen($key) !== 8)
{
    echo "bad \n";  
    exit(1);
}
*/
$b=str_split($msg);
$count=count($b);
$key_bin="";
$i=0;
//<FIRST STEP KEY ASCII TO BINARY>
for ($i=0;$i<8;$i++)
{
    $bin=decbin(ord($key[$i]));
    $bin = substr("00000000",0,8 - strlen($bin)) . $bin;
    $key_bin= $key_bin . $bin;

}
//$key_bin="0001001100110100010101110111100110011011101111001101111111110001";
echo "\n\t\t0000000001111111111222222222233333333334444444444555555555566666\n";
echo"\t\t1234567890123456789012345678901234567890123456789012345678901234\n";
echo "\nBinary key: \t$key_bin\n";
//</FIRST STEP KEY ASCII TO BINARY>
//<permuting> //controllata
$permutedkey= 
$key_bin[56] . $key_bin[48] . $key_bin[40] . $key_bin[32] . $key_bin[24] . $key_bin[16] . $key_bin[8] . 
$key_bin[0] . $key_bin[57] . $key_bin[49] . $key_bin[41] . $key_bin[33] . $key_bin[25] . $key_bin[17] . 
$key_bin[9] . $key_bin[1] . $key_bin[58] . $key_bin[50] . $key_bin[42] . $key_bin[34] . $key_bin[26] . 
$key_bin[18] . $key_bin[10] . $key_bin[2] . $key_bin[59] . $key_bin[51] . $key_bin[43] . $key_bin[35] .
 $key_bin[62] . $key_bin[54] . $key_bin[46] . $key_bin[38] . $key_bin[30] . $key_bin[22] . $key_bin[14] . 
$key_bin[6] . $key_bin[61] . $key_bin[53] . $key_bin[45] . $key_bin[37] . $key_bin[29] . $key_bin[21] .
$key_bin[13] . $key_bin[5] . $key_bin[60] . $key_bin[52] . $key_bin[44] . $key_bin[36] . $key_bin[28] .
 $key_bin[20] . $key_bin[12] . $key_bin[4] . $key_bin[27] . $key_bin[19] . $key_bin[11] . $key_bin[3];
//</permuting>

echo "Permuted key: \t$permutedkey\n\n\n"; 
$C[0]=substr($permutedkey,0,28);
$D[0]=substr($permutedkey,28,56);
//echo "C0:\t$C[0]\n";
//echo "D0:\t$D[0]\n";
echo "\tC\t\t\t\tD\t\t\t\tshifts\n";
echo "0\t$C[0]\t$D[0]\tnull\n";

//<shifting>
$how_many_shifts=[1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];
for($i=1;$i<=16;$i++)
{
    $first_digits_C=substr($C[$i-1],0,$how_many_shifts[$i-1]); //array starts index 0
    $C[$i]=substr($C[$i-1],$how_many_shifts[$i-1],28) . $first_digits_C;
    $first_digits_D=substr($D[$i-1],0,$how_many_shifts[$i-1]);
    $D[$i]=substr($D[$i-1],$how_many_shifts[$i-1],28) . $first_digits_D;
    echo "$i\t$C[$i]\t$D[$i]\t";
    echo $how_many_shifts[$i-1] . "\n";
}
//</shifting>
for($i=1;$i<=16;$i++)
{
$K[$i]="";
}
//<permuting>
echo "\nPermuting:\n";
echo"\tPermuting...\t\t\t\t\t\t\tPermuted...\n";
echo"\t00000000011111111112222222222333333333344444444445555555\t000000000111111111122222222223333333333444444444\n";
echo"\t12345678901234567890123456789012345678901234567890123456\t123456789012345678901234567890123456789012345678\n\n";
for($i=1;$i<=16;$i++)
{
echo "C$i". "D$i\t";
$chained=$C[$i] . $D[$i];
$K[$i]=$chained[13] . $chained[16] . $chained[10] . $chained[23] . $chained[0] . $chained[4] . $chained[2] . $chained[27] . $chained[14] . $chained[5] . $chained[20] . $chained[9] . $chained[22] . $chained[18] . $chained[11] . $chained[3] . $chained[25] . $chained[7] . $chained[15] . $chained[6] . $chained[26] . $chained[19] . $chained[12] . $chained[1] . $chained[40] . $chained[51] . $chained[30] . $chained[36] . $chained[46] . $chained[54] . $chained[29] . $chained[39] . $chained[50] . $chained[44] . $chained[32] . $chained[47] .$chained[43] . $chained[48] . $chained[38] . $chained[55] . $chained[33] . $chained[52] . $chained[45] . $chained[41] . $chained[49] . $chained[35] . $chained[28] . $chained[31] ;
echo "$chained\t" . "$K[$i]\n";
}
//</permuting>
$msg_bin="";
//<FIRST STEP MSG ASCII TO BINARY>
for ($i=0;$i<8;$i++)
{
    $ascii_msg=decbin(ord($msg[$i]));
    $ascii_msg_formatted = substr("00000000",0,8 - strlen($ascii_msg)) . $ascii_msg;
    $msg_bin= $msg_bin . $ascii_msg_formatted;

}
//$msg_bin="0000000100100011010001010110011110001001101010111100110111101111";

echo "\n\t\t0000000001111111111222222222233333333334444444444555555555566666\n";
echo"\t\t1234567890123456789012345678901234567890123456789012345678901234\n";
echo "Binary msg: \t$msg_bin\n";
//</FIRST STEP MSG ASCII TO BINARY>
//<permuting msg>controllata
$permuted_msg=
$msg_bin[57] . $msg_bin[49] . $msg_bin[41] . $msg_bin[33] . $msg_bin[25] . $msg_bin[17] . $msg_bin[9] . $msg_bin[1] . 
$msg_bin[59] . $msg_bin[51] . $msg_bin[43] . $msg_bin[35] . $msg_bin[27] . $msg_bin[19] . $msg_bin[11] . $msg_bin[3] .
$msg_bin[61] . $msg_bin[53] . $msg_bin[45] . $msg_bin[37] . $msg_bin[29] . $msg_bin[21] . $msg_bin[13] . $msg_bin[5] .
$msg_bin[63] . $msg_bin[55] . $msg_bin[47] . $msg_bin[39] . $msg_bin[31] . $msg_bin[23] . $msg_bin[15] . $msg_bin[7] .
$msg_bin[56] . $msg_bin[48] . $msg_bin[40] . $msg_bin[32] . $msg_bin[24] . $msg_bin[16] . $msg_bin[8] . $msg_bin[0] .
$msg_bin[58] . $msg_bin[50] . $msg_bin[42] . $msg_bin[34] . $msg_bin[26] . $msg_bin[18] . $msg_bin[10] . $msg_bin[2] .
 $msg_bin[60] . $msg_bin[52] . $msg_bin[44] . $msg_bin[36] . $msg_bin[28] . $msg_bin[20] . $msg_bin[12] . $msg_bin[4] . 
$msg_bin[62] . $msg_bin[54] . $msg_bin[46] . $msg_bin[38] . $msg_bin[30] . $msg_bin[22] . $msg_bin[14] . $msg_bin[6];


for($i=0;$i<=64;$i++) //per l'uso che farò di queste variabili, possono anche non essere array, ma sono utili per il debug
    {
    $L[$i]="";      
    $R[$i]="";
    $ERf[$i]="";
    $xored[$i]="";
    $substitution[$i]="";
    $conversion[$i]="";
    $f[$i]="";
    }

//</permuting msg>
echo "Permuted msg:\t$permuted_msg\n";
$L[0]=substr($permuted_msg,0,32);
$R[0]=substr($permuted_msg,32,32);
//echo "L0:\t$L[0]\n";
//echo "R0:\t$R[0]\n";
//echo "L[2]:\t" . substr($L[0],7,1) . "\n";

//PART 3:ITERATIONS
$cont=0;
$xored="";
$i=1;
echo "\n\t\t\t000000000111111111122222222223333333444444444444\n";
echo"\t\t\t123456789012345678901234567890123456789012345678\n";
for ($i=1;$i<=16;$i++)  //MODIFICARE IN 16
{

$L[$i]=$R[$i-1];

$ERf[$i-1]=
substr($R[$i-1],31,1) . substr($R[$i-1],0,1) . substr($R[$i-1],1,1) . substr($R[$i-1],2,1) . substr($R[$i-1],3,1) . substr($R[$i-1],4,1) . 
substr($R[$i-1],3,1) . substr($R[$i-1],4,1) . substr($R[$i-1],5,1) . substr($R[$i-1],6,1) . substr($R[$i-1],7,1) . substr($R[$i-1],8,1) .
substr($R[$i-1],7,1) . substr($R[$i-1],8,1) .  substr($R[$i-1],9,1) . substr($R[$i-1],10,1) . substr($R[$i-1],11,1) . substr($R[$i-1],12,1) . substr($R[$i-1],11,1) . substr($R[$i-1],12,1) . substr($R[$i-1],13,1) . substr($R[$i-1],14,1) . substr($R[$i-1],15,1) . substr($R[$i-1],16,1) . substr($R[$i-1],15,1) . substr($R[$i-1],16,1) . substr($R[$i-1],17,1) . substr($R[$i-1],18,1) . substr($R[$i-1],19,1) . substr($R[$i-1],20,1) . substr($R[$i-1],19,1) . substr($R[$i-1],20,1) . substr($R[$i-1],21,1) . substr($R[$i-1],22,1) . substr($R[$i-1],23,1) . substr($R[$i-1],24,1) . substr($R[$i-1],23,1) . substr($R[$i-1],24,1) . substr($R[$i-1],25,1) . substr($R[$i-1],26,1) . substr($R[$i-1],27,1) . substr($R[$i-1],28,1) . substr($R[$i-1],27,1) . substr($R[$i-1],28,1) . substr($R[$i-1],29,1) . substr($R[$i-1],30,1) . substr($R[$i-1],31,1) . substr($R[$i-1],0,1);
$temp="";
$temp1="";  
    //<ciclo xor a modo mio sommo ogni bit all'iesima posizione, creo una stringa fatta da o 0 o 1 o 2 e rimpiazzo il 2 con 0>
    for ($cont=0;$cont<48;$cont++)
        {
        //echo "$i x $cont)";
        $temp.=(int)(substr($K[$i],$cont,1)) + (int)(substr($ERf[$i-1],$cont,1));
        //echo "\n";
        }
    //</ciclo xor>
$temp=str_replace("2","0",$temp);
$xored[$i]=$temp;

//OK
//echo "CONT\n";
//S-BOX TRANSFORMATION
for($cont=0;$cont<8;$cont++)
    {//cont for
    $chunk[$cont]=substr($xored[$i],(6*$cont),6);
    $first[$cont]=substr($chunk[$cont],0,1);
    $last[$cont]=substr($chunk[$cont],-1,1);
    $row[$cont]=substr($chunk[$cont],1,4);
    $row_dec[$cont]=bindec("0000" . $row[$cont]);
    $column_dec[$cont]=bindec("000000" . $first[$cont] . $last[$cont]);
    //echo "$cont $chunk[$cont] $column_dec[$cont] $row_dec[$cont] \n";
    switch($cont+1)
        {//switch
        case 1:
            $substitution[$cont]=$SANDBOX_1[$column_dec[$cont]][$row_dec[$cont]];
            break;
        case 2:
            $substitution[$cont]=$SANDBOX_2[$column_dec[$cont]][$row_dec[$cont]];
            break;
        case 3:
            $substitution[$cont]=$SANDBOX_3[$column_dec[$cont]][$row_dec[$cont]];
            break;
        case 4:
            $substitution[$cont]=$SANDBOX_4[$column_dec[$cont]][$row_dec[$cont]];
            break;
        case 5:
            $substitution[$cont]=$SANDBOX_5[$column_dec[$cont]][$row_dec[$cont]];
            break;
        case 6:
            $substitution[$cont]=$SANDBOX_6[$column_dec[$cont]][$row_dec[$cont]];
            break;
        case 7:
            $substitution[$cont]=$SANDBOX_7[$column_dec[$cont]][$row_dec[$cont]];
            break;
        case 8:
            $substitution[$cont]=$SANDBOX_8[$column_dec[$cont]][$row_dec[$cont]];
            break;  
        }   //switch
    $substituted=decbin($substitution[$cont]);
    $substituted = substr("0000",0,4-strlen($substituted)) . $substituted;
    $replace.=$substituted;                                 
    } //for cont
$sand[$i]=$replace;

//P permutation
$f[$i]=substr($replace,15,1) . substr($replace,6,1) . substr($replace,19,1) . substr($replace,20,1) . substr($replace,28,1) . substr($replace,11,1) . substr($replace,27,1) . substr($replace,16,1) . substr($replace,0,1) . substr($replace,14,1) . substr($replace,22,1) . substr($replace,25,1) . substr($replace,4,1) . substr($replace,17,1) .  substr($replace,30,1) . substr($replace,9,1) . substr($replace,1,1) . substr($replace,7,1) . substr($replace,23,1) . substr($replace,13,1) . substr($replace,31,1) . substr($replace,26,1) . substr($replace,2,1) . substr($replace,8,1) . substr($replace,18,1) . substr($replace,12,1) . substr($replace,29,1) . substr($replace,5,1) . substr($replace,21,1) . substr($replace,10,1) . substr($replace,3,1) . substr($replace,24,1);

//final permutation

for ($cont=0;$cont<32;$cont++)
        {
        $temp1.=(int)(substr($f[$i],$cont,1)) + (int)(substr($L[$i-1],$cont,1));

        }
    //</ciclo xor>
$temp1=str_replace("2","0",$temp1);
$R[$i]=$temp1;

echo "$i\t";
echo "E(R" . ($i-1) . ")\t\t".$ERf[$i-1]."\t 48 bit\n";
echo "\tK[$i]\t\t$K[$i]\t 48 bit\n";
echo "\txor\t\t$xored[$i]\t 48 bit\n";
echo "\tsand\t\t$sand[$i]\n\n";
echo "\tL[$i]\t\t$L[$i]\t\t\t 32 bit\n";
echo "\tPsand=f\t\t" . $f[$i] . "\t\t\t 32 bit\n";
echo "\tL[" . ($i-1) . "]\t\t" . $L[$i-1] . "\t\t\t 32 bit\n";
echo "\txor=R[$i]\t$R[$i]\t\t\t 32 bit\n\n\n";


$temp="";
$f="";
$replace="";
$substituted=""; 

}
$R16L16=$R[16] . $L[16];
echo "Reversed:\t\t$R16L16\n";
$encrypted=
$R16L16[39] . $R16L16[7] . $R16L16[47] . $R16L16[15] . $R16L16[55] . $R16L16[23] . $R16L16[63] . $R16L16[31] . 
$R16L16[38] . $R16L16[6] . $R16L16[46] . $R16L16[14] . $R16L16[54] . $R16L16[22] . $R16L16[62] . $R16L16[30] . 
$R16L16[37] . $R16L16[5] . $R16L16[45] . $R16L16[13] . $R16L16[53] . $R16L16[21] . $R16L16[61] . $R16L16[29] . 
$R16L16[36] . $R16L16[4] . $R16L16[44] . $R16L16[12] . $R16L16[52] . $R16L16[20] . $R16L16[60] . $R16L16[28] . 
$R16L16[35] . $R16L16[3] . $R16L16[43] . $R16L16[11] . $R16L16[51] . $R16L16[19] . $R16L16[59] . $R16L16[27] .
$R16L16[34] . $R16L16[2] . $R16L16[42] . $R16L16[10] . $R16L16[50] . $R16L16[18] . $R16L16[58] . $R16L16[26] . 
$R16L16[33] . $R16L16[1] . $R16L16[41] . $R16L16[9] . $R16L16[49] . $R16L16[17] . $R16L16[57] . $R16L16[25] . 
$R16L16[32] . $R16L16[0] . $R16L16[40] . $R16L16[8] . $R16L16[48] . $R16L16[16] .  $R16L16[56] . $R16L16[24];
echo "\n\nEncrypted:\t\t$encrypted\n";
//echo "CONVERSION\n";
//BASE64
$m=0;
$encrypted.="00";
for($m=0;$m<=10;$m++)
    {
    $conv=substr($encrypted,6*$m,6);
    $ris=32*$conv[0]+16*$conv[1]+8*$conv[2]+4*$conv[3]+2*$conv[4]+$conv[5];
    if($ris<=25)
        $ris+=65;
    if($ris>25 && $ris<=51)
        $ris+=71;
    if($ris>51 && $ris<=61)
        $ris+=48;
    if($ris==62)
        $ris=43;
    if($ris==63)
        $ris=47;
    echo chr($ris);
    }
echo"=\n";
?>

And here the output

***************************************************************************
|                    DES ENCODING ALGORITHM                               |
|                    sat 29 aug 2015                                      |
|                                                                  |
***************************************************************************

        0000000001111111111222222222233333333334444444444555555555566666
        1234567890123456789012345678901234567890123456789012345678901234

Binary key:     0100000101000001010000010100000101000001010000010100000101000001
Permuted key:   00000000111111110000000000000000000000000000000000000000


    C               D               shifts
0   0000000011111111000000000000    0000000000000000000000000000    null
1   0000000111111110000000000000    0000000000000000000000000000    1
2   0000001111111100000000000000    0000000000000000000000000000    1
3   0000111111110000000000000000    0000000000000000000000000000    2
4   0011111111000000000000000000    0000000000000000000000000000    2
5   1111111100000000000000000000    0000000000000000000000000000    2
6   1111110000000000000000000011    0000000000000000000000000000    2
7   1111000000000000000000001111    0000000000000000000000000000    2
8   1100000000000000000000111111    0000000000000000000000000000    2
9   1000000000000000000001111111    0000000000000000000000000000    1
10  0000000000000000000111111110    0000000000000000000000000000    2
11  0000000000000000011111111000    0000000000000000000000000000    2
12  0000000000000001111111100000    0000000000000000000000000000    2
13  0000000000000111111110000000    0000000000000000000000000000    2
14  0000000000011111111000000000    0000000000000000000000000000    2
15  0000000001111111100000000000    0000000000000000000000000000    2
16  0000000011111111000000000000    0000000000000000000000000000    1

Permuting:
    Permuting...                            Permuted...
    00000000011111111112222222222333333333344444444445555555    000000000111111111122222222223333333333444444444
    12345678901234567890123456789012345678901234567890123456    123456789012345678901234567890123456789012345678

C1D1    00000001111111100000000000000000000000000000000000000000    101000001001001001000010000000000000000000000000
C2D2    00000011111111000000000000000000000000000000000000000000    101000000001001001010010000000000000000000000000
C3D3    00001111111100000000000000000000000000000000000000000000    001001000101001001010000000000000000000000000000
C4D4    00111111110000000000000000000000000000000000000000000000    000001100101000101010000000000000000000000000000
C5D5    11111111000000000000000000000000000000000000000000000000    000011100100000101010001000000000000000000000000
C6D6    11111100000000000000000000110000000000000000000000000000    000011110100000100001001000000000000000000000000
C7D7    11110000000000000000000011110000000000000000000000000000    000010110000000110001001000000000000000000000000
C8D8    11000000000000000000001111110000000000000000000000000000    000110010000100010001001000000000000000000000000
C9D9    10000000000000000000011111110000000000000000000000000000    000110010000100010001000000000000000000000000000
C10D10  00000000000000000001111111100000000000000000000000000000    000100000010100010001100000000000000000000000000
C11D11  00000000000000000111111110000000000000000000000000000000    000100000010110000000100000000000000000000000000
C12D12  00000000000000011111111000000000000000000000000000000000    010000000010110000100100000000000000000000000000
C13D13  00000000000001111111100000000000000000000000000000000000    110000001010010000100100000000000000000000000000
C14D14  00000000000111111110000000000000000000000000000000000000    110000001000011000100010000000000000000000000000
C15D15  00000000011111111000000000000000000000000000000000000000    111000001001001000100010000000000000000000000000
C16D16  00000000111111110000000000000000000000000000000000000000    101000001001001000100010000000000000000000000000

        0000000001111111111222222222233333333334444444444555555555566666
        1234567890123456789012345678901234567890123456789012345678901234
Binary msg:     0100000101000001010000010100000101000001010000010100000101000001
Permuted msg:   1111111100000000000000001111111100000000000000000000000000000000

            000000000111111111122222222223333333444444444444
            123456789012345678901234567890123456789012345678
1   E(R0)       000000000000000000000000000000000000000000000000     48 bit
    K[1]        101000001001001001000010000000000000000000000000     48 bit
    xor     101000001001001001000010000000000000000000000000     48 bit
    sand        11011111001111010010110001001101

    L[1]        00000000000000000000000000000000             32 bit
    Psand=f     11011100100110001101100011111110             32 bit
    L[0]        11111111000000000000000011111111             32 bit
    xor=R[1]    00100011100110001101100000000001             32 bit


2   E(R1)       100100000111110011110001011011110000000000000010     48 bit
    K[2]        101000000001001001010010000000000000000000000000     48 bit
    xor     001100000110111010100011011011110000000000000010     48 bit
    sand        10111110101011111001011101000010

    L[2]        00100011100110001101100000000001             32 bit
    Psand=f     11100001111110100011001101011110             32 bit
    L[1]        00000000000000000000000000000000             32 bit
    xor=R[2]    11100001111110100011001101011110             32 bit


3   E(R2)       011100000011111111110100000110100110101011111101     48 bit
    K[3]        001001000101001001010000000000000000000000000000     48 bit
    xor     010101000110110110100100000110100110101011111101     48 bit
    sand        11001110110010010001010101000110

    L[3]        11100001111110100011001101011110             32 bit
    Psand=f     11100000100110111010000101111000             32 bit
    L[2]        00100011100110001101100000000001             32 bit
    xor=R[3]    11000011000000110111100101111001             32 bit


4   E(R3)       111000000110100000000110101111110010101111110011     48 bit
    K[4]        000001100101000101010000000000000000000000000000     48 bit
    xor     111001100011100101010110101111110010101111110011     48 bit
    sand        10101000110101011101000001111100

    L[4]        11000011000000110111100101111001             32 bit
    Psand=f     10101111100111010001011100100000             32 bit
    L[3]        11100001111110100011001101011110             32 bit
    xor=R[4]    01001110011001110010010001111110             32 bit


5   E(R4)       001001011100001100001110100100001000001111111100     48 bit
    K[5]        000011100100000101010001000000000000000000000000     48 bit
    xor     001010111000001001011111100100001000001111111100     48 bit
    sand        11111001001110010001100110100101

    L[5]        01001110011001110010010001111110             32 bit
    Psand=f     10110100100010001110111001100111             32 bit
    L[4]        11000011000000110111100101111001             32 bit
    xor=R[5]    01110111100010111001011100011110             32 bit


6   E(R5)       001110101111110001010111110010101110100011111100     48 bit
    K[6]        000011110100000100001001000000000000000000000000     48 bit
    xor     001101011011110101011110110010101110100011111100     48 bit
    sand        11011001111011111001001110110101

    L[6]        01110111100010111001011100011110             32 bit
    Psand=f     10100011111010011111110101100111             32 bit
    L[5]        01001110011001110010010001111110             32 bit
    xor=R[6]    11101101100011101101100100011001             32 bit


7   E(R6)       111101011011110001011101011011110010100011110011     48 bit
    K[7]        000010110000000110001001000000000000000000000000     48 bit
    xor     111111101011110111010100011011110010100011110011     48 bit
    sand        00011111001110001001000010111100

    L[7]        11101101100011101101100100011001             32 bit
    Psand=f     01101111000010000100010001110111             32 bit
    L[6]        01110111100010111001011100011110             32 bit
    xor=R[7]    00011000100000111101001101101001             32 bit


8   E(R7)       100011110001010000000111111010100110101101010010     48 bit
    K[8]        000110010000100010001001000000000000000000000000     48 bit
    xor     100101100001110010001110111010100110101101010010     48 bit
    sand        10001101000110100011010110101001

    L[8]        00011000100000111101001101101001             32 bit
    Psand=f     00101100110010000110110011011001             32 bit
    L[7]        11101101100011101101100100011001             32 bit
    xor=R[8]    11000001010001101011010111000000             32 bit


9   E(R8)       011000000010101000001101010110101011111000000001     48 bit
    K[9]        000110010000100010001000000000000000000000000000     48 bit
    xor     011110010010001010000101010110101011111000000001     48 bit
    sand        01110111001110111111010100000001

    L[9]        11000001010001101011010111000000             32 bit
    Psand=f     11100101010001001110101011011110             32 bit
    L[8]        00011000100000111101001101101001             32 bit
    xor=R[9]    11111101110001110011100110110111             32 bit


10  E(R9)       111111111011111000001110100111110011110110101111     48 bit
    K[10]       000100000010100010001100000000000000000000000000     48 bit
    xor     111011111001011010000010100111110011110110101111     48 bit
    sand        00000000010011010111111010001101

    L[10]       11111101110001110011100110110111             32 bit
    Psand=f     10111000001001010001100011101001             32 bit
    L[9]        11000001010001101011010111000000             32 bit
    xor=R[10]   01111001011000111010110100101001             32 bit


11  E(R10)      101111110010101100000111110101011010100101010010     48 bit
    K[11]       000100000010110000000100000000000000000000000000     48 bit
    xor     101011110000011100000011110101011010100101010010     48 bit
    sand        10010101001010000000011111011001

    L[11]       01111001011000111010110100101001             32 bit
    Psand=f     00001010101100000110100001011111             32 bit
    L[10]       11111101110001110011100110110111             32 bit
    xor=R[11]   11110111011101110101000111101000             32 bit


12  E(R11)      011110101110101110101110101010100011111101010001     48 bit
    K[12]       010000000010110000100100000000000000000000000000     48 bit
    xor     001110101100011110001010101010100011111101010001     48 bit
    sand        10001101100001101101001100111100

    L[12]       11110111011101110101000111101000             32 bit
    Psand=f     00101011111011000111010100110000             32 bit
    L[11]       01111001011000111010110100101001             32 bit
    xor=R[12]   01010010100011111101100000011001             32 bit


13  E(R12)      101010100101010001011111111011110000000011110010     48 bit
    K[13]       110000001010010000100100000000000000000000000000     48 bit
    xor     011010101111000001111011111011110000000011110010     48 bit
    sand        10010010110101110100011100000110

    L[13]       01010010100011111101100000011001             32 bit
    Psand=f     11000100111001110011000100101010             32 bit
    L[12]       11110111011101110101000111101000             32 bit
    xor=R[13]   00110011100100000110000011000010             32 bit


14  E(R13)      000110100111110010100000001100000001011000000100     48 bit
    K[14]       110000001000011000100010000000000000000000000000     48 bit
    xor     110110101111101010000010001100000001011000000100     48 bit
    sand        01110010111111011011101001011000

    L[14]       00110011100100000110000011000010             32 bit
    Psand=f     11111111001100011001001111000110             32 bit
    L[13]       01010010100011111101100000011001             32 bit
    xor=R[14]   10101101101111100100101111011111             32 bit


15  E(R14)      110101011011110111111100001001010111111011111111     48 bit
    K[15]       111000001001001000100010000000000000000000000000     48 bit
    xor     001101010010111111011110001001010111111011111111     48 bit
    sand        11010111110011110100111000101011

    L[15]       10101101101111100100101111011111             32 bit
    Psand=f     11011000111001111101110101011010             32 bit
    L[14]       00110011100100000110000011000010             32 bit
    xor=R[15]   11101011011101111011110110011000             32 bit


16  E(R15)      011101010110101110101111110111111011110011110001     48 bit
    K[16]       101000001001001000100010000000000000000000000000     48 bit
    xor     110101011111100110001101110111111011110011110001     48 bit
    sand        00110101100100001001000001011111

    L[16]       11101011011101111011110110011000             32 bit
    Psand=f     00101111000100100100101100110010             32 bit
    L[15]       10101101101111100100101111011111             32 bit
    xor=R[16]   10000010101011000000000011101101             32 bit


Reversed:       1000001010101100000000001110110111101011011101111011110110011000


Encrypted:      1010100111100000001110011001101100101010101110011010000111011011
qeAimyqiods=

I receive as output

 qeAimyqiods=

Problem is that if I visit http://www.tools4noobs.com/online_tools/encrypt/, I get output

Gd+ErJVVEAM=

Where am I wrong?

I'm a beginner

Thanks

share|improve this question

closed as off-topic by Simon Forsberg Aug 30 at 12:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Simon Forsberg
If this question can be reworded to fit the rules in the help center, please edit the question.

    
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information. –  Simon Forsberg Aug 30 at 12:20