fork(1) download
  1. #!/usr/bin/perl
  2.  
  3. # Idiom #307 XOR encrypt/decrypt string
  4.  
  5. sub xor_crypt {
  6. my ($b, $k) = @_;
  7. return $b ^ $k;
  8. }
  9.  
  10. my $b = 0b110010001101;
  11. my $k = 0b011000101001;
  12.  
  13. printf "bitstring: %012b\n", $b;
  14. printf "key: %012b\n", $k;
  15. printf "xor result: %012b\n", xor_crypt($b, $k);
  16.  
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
bitstring:  110010001101
key:        011000101001
xor result: 101010100100