Here's how you figure out how to de-obfuscate this routine.
Sorry for the length
First let me remove the code and add some useful comments.
sub foo {
[
(
$#{
$_[
! ( $| | $| )
]
}
*
@{
$_[
!!$_ ^ !$_
]
}
)
?
@{
$_[
!$. . !!$.
]
}
[
$_[
@- - @+
]
%
@{
$_[
$= =~ /(?=)/ / !$`
]
}
..
$#{
$_[
$? ? !!$? : !$?
]
}
,
(
$) ? !$) : !!$)
)
..
$_[
$- - $-
]
%
@{
$_[
$] / $]
]
}
-
(
!!$+ + !$+
)
]
:
@{
$_[
!!$^^ ^ !$^^
]
}
]
}
Now remove the obfuscation portion.
sub foo{
[
(
$#{$_[1]} * @{$_[1]}
)
?
@{$_[1]}[
( $_[0] % @{$_[1]} ) .. $#{$_[1]}
,
0 .. ( $_[0] % @{$_[1]} - 1 )
]
:
@{$_[1]}
]
}
Now that we have some idea of what is going on, let me name the variables.
sub foo{
my( $item_0, $arr_1 ) = @_;
my $len_1 = @$arr_1;
[
( ( $len_1 -1 ) * $len_1 )
?
@{$arr_1}[
( $item_0 % $len_1 ) .. ( $len_1 -1 ),
0 .. ( $item_0 % $len_1 - 1 )
]
:
@$arr_1
]
}
Let us reorganize the code to make it more readable.
sub foo{
my( $item_0, $arr_1 ) = @_;
my $len_1 = @$arr_1;
if( $len_1 > 1 ){
return [
@{$arr_1}[
( $item_0 % $len_1 ) .. ( $len_1 -1 ),
0 .. ( $item_0 % $len_1 - 1 )
]
];
}elsif( $len_1 ){
return [ @$arr_1 ];
}else{
return [];
}
}
source
share