Sujet : Re: Efficient dword bitwise rotate / circular shift using Bash shell ?
De : jb-usenet (at) *nospam* wisemo.invalid (Jakob Bohm)
Groupes : sci.cryptDate : 15. May 2024, 12:33:01
Autres entêtes
Organisation : WiseMo A/S
Message-ID : <v226he$rhfh$1@dont-email.me>
References : 1 2
User-Agent : Epyrus/2.1.2
On 2024-05-11 17:37, Phil Carmody wrote:
SugarBug <3883@sugar.bug> writes:
Example:
>
rol() { num="$@" ; pre=$((num<<13)) ; suf=$((num>>19)) ;
num=$((pre^suf)) ; num=$((num&0xffffffff)) ; echo "$num" ; }
>
What tricks will make this more efficient in Bash?
If you can be sure the input will never be 0xffffffff, then this should
work:
rol () { echo "$(($1*8192%0xffffffff))" ; }
Phil
rol13() { printf '0x%X' $(((($1<<13)+($1>>19))&0xffffffff))
}
Avoids that limitation, but may be slightly slower depending on bash inefficiencies.
Enjoy
Jakob
-- Jakob Bohm, CIO, Partner, WiseMo A/S. https://www.wisemo.comTransformervej 29, 2860 Søborg, Denmark. Direct +45 31 13 16 10This public discussion message is non-binding and may contain errors.WiseMo - Remote Service Management for PCs, Phones and Embedded