#!/usr/bin/perl use strict; use warnings 'all'; use Config; my $longsize = $Config{longsize}; my $firstbit = ($longsize * 8) - 1; sub rshift { # Should be signed/sign-propagating right shift my ($x, $y) = @_; foreach (my $i = 0; $i < $y; $i++) { my $lbit = (($x & (1 << $firstbit)) != 0); $x = ($x >> 1) | ((1 << $firstbit) * $lbit); } return unpack("l>", pack("l>", $x)); } sub bin_test_print { printf("%032b = %d\n", $_[0], $_[0]); } my $x = 9; bin_test_print($x); $x = rshift($x, 2); bin_test_print($x); print "\n\n"; $x = -9; bin_test_print($x); $x = rshift($x, 2); bin_test_print($x); print "\n\n"; $x = 12345; bin_test_print($x); $x = rshift($x, 2); bin_test_print($x); print "\n\n"; $x = -12345; bin_test_print($x); $x = rshift($x, 2); bin_test_print($x); #### use strict; use warnings 'all'; use MIME::Base64; sub b64_password { return MIME::Base64::encode($_[0]); } sub b64_utf16_password { my @ascii = unpack("C*", $_[0]); my $utf16 = pack("v*", @ascii); my $base64_utf16 = MIME::Base64::encode($utf16); return $base64_utf16; }