"Sputnik" help  
Sputnik Help
BinarySpin(<binary>, [<rot>], [<start>], [<length>])

Description

The BinarySpin function is used to spin or rotate a portion of a binary string by a specified amount. The spinning operation involves shifting the byte values in the specified range either clockwise or counterclockwise. The function returns a new binary string with the spun portion.

Parameters

<binary> The original binary string to be spun.
<rot> Optional rotation amount. A positive value rotates the bytes clockwise, and a negative value rotates them counterclockwise. (Default: 255)
<start> Optional starting index of the portion to be spun. A negative value indicates counting from the end of the binary string. (Default: 0)
<length> Optional length of the portion to be spun. If not specified, the spinning operation applies to the remaining bytes in the binary string from the starting index to the end. (Default: Full length from the starting index to the end)

Return Value

Success: Returns a new binary string with the spun portion.
Failure: Returns an empty binary string.

Remarks

The BinarySpin function performs a spinning operation on the specified portion of the binary string, where the bytes are shifted by the rotation amount. The rotation can be either clockwise or counterclockwise based on the provided rotation value.

If the rotation amount is positive, the bytes in the specified range are rotated clockwise. This means that each byte is shifted to the right by the rotation amount, and the rightmost bytes wrap around to the left.

If the rotation amount is negative, the bytes in the specified range are rotated counterclockwise. This means that each byte is shifted to the left by the absolute value of the rotation amount, and the leftmost bytes wrap around to the right.

The start and length parameters define the range of bytes to be spun. If the start parameter is not specified, the spinning operation starts from the beginning of the binary string. If the length parameter is not specified, the spinning operation applies to the remaining bytes in the binary string from the starting index to the end.

If the start or length values are negative, they indicate counting from the end of the binary string. If the binary string is empty or the start or length values are out of bounds, the function returns an empty binary string.

Related

Example

Example of usage:

my $binary = BinaryFromStr("Hello, World");
my $result1 = BinarySpin($binary);
my $result2 = BinarySpin($binary, 4, 3);
my $result3 = BinarySpin($binary, -5, 6);
my $result4 = BinarySpin($binary, 1, 2, 3);
say $result1;
say $result2;
say $result3;
say $result4;

// PRINTS
// Ifmmp-!Xpsme
// Helhk(Sknh`
// Hello,审
// Hekkn, World

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org