Data Encryption Standard: Difference between revisions
Content added Content deleted
m (→{{header|Perl 6}}: try replacing pack/unpack) |
|||
Line 2,545: | Line 2,545: | ||
use v6.d; |
use v6.d; |
||
use experimental :pack; |
#use experimental :pack; |
||
my \PC1 = < |
my \PC1 = < |
||
Line 2,613: | Line 2,613: | ||
# convert iso-8859-1 to hexadecimals |
# convert iso-8859-1 to hexadecimals |
||
sub b2h (\b) { [~] map { .encode('iso-8859-1').unpack('H*') }, b.comb }; |
#sub b2h (\b) { [~] map { .encode('iso-8859-1').unpack('H*') }, b.comb }; |
||
sub b2h (\b) { b.ords.fmt('%02X', '') }; |
|||
# convert UTF8s to bytes |
# convert UTF8s to bytes |
||
sub u2b (\u) { [~] map { .chr }, @( [~] map { .encode('utf8') }, u.comb) }; |
sub u2b (\u) { [~] map { .chr }, @( [~] map { .encode('utf8') }, u.comb) }; |
||
# convert hexadecimals to UTF-8 |
# convert hexadecimals to UTF-8 |
||
sub h2u (\h) { pack("H" x h.chars/2, h ~~ m:g/../).decode('utf8') }; |
#sub h2u (\h) { pack("H" x h.chars/2, h ~~ m:g/../).decode('utf8') }; |
||
sub h2u (\h) { Blob.new( h.comb(2).map: { :16( $_ ) } ).decode('utf8') }; |
|||
# convert quadbits to hex |
# convert quadbits to hex |
||
sub q2h (\q) { [~] map { :2($_.Str).fmt('%X') }, q ~~ m:g/..../ }; |
sub q2h (\q) { [~] map { :2($_.Str).fmt('%X') }, q ~~ m:g/..../ }; |