ETOOBUSY ๐ minimal blogging for the impatient
Cryptopals 2 - Fixed XOR
TL;DR
Challenge 2 is almost trivial in Perl, thanks to how operator
^
works. Or I should probably say operator ^.
, which is
enabled by default starting from perl v5.28
on (or use feature
"bitwise";
starting from perl v5.22
).
So here we go:
sub fixed_xor ($string1, $string2) { $string1 ^. $string2 }
As indicated in the challenge, of course we have to do a bit of back and forth with decoding the input (provided in hex form) and encoding it back before printing it:
my $in1 = '1c0111001f010100061a024b53535009181c';
my $in2 = '686974207468652062756c6c277320657965';
my $out = '746865206b696420646f6e277420706c6179';
say encode_base16(fixed_xor(decode_base16($in1), decode_base16($in2)));
say $out;
Function encode_base16
and decode_base16
are the same from the
previous post Cryptopals 1 - Convert hex to base64.
Stay safe and secure!