in reply to Re^2: Rewriting a C# Encryption Function
in thread Rewriting a C# Encryption Function
Sadly you can skip unicode madness only if you know that the strings you have to convert are all from a very limited set of chars (a-z,A-Z,0-9 and a few special chars). Then using just the pack method would be enough.
But the link I provided seems to have the solution on a platter:
my $octets= encode("utf16", '1234'); $octets= substr($octets,2); for my $i (0..(length($octets)/2-1)) { my $n= substr($octets,$i*2,1); substr( $octets,$i*2,1)= substr($octets,$i*2+1,1); substr($octets,$i*2+1,1)=$n; } print sha1_base64($octets);
prints out 'E59py...'. The really ugly for loop swaps the bytes of one 16 bit value since the encoding was swapped on my machine. If you don't get the same result, drop the for loop and check again.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Rewriting a C# Encryption Function
by graff (Chancellor) on Aug 23, 2008 at 00:14 UTC |