File: xor_cipher.pl

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (29 lines) | stat: -rw-r--r-- 725 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use strict;
use warnings;
use FFI::Platypus 2.00;
use FFI::Platypus::Buffer qw( buffer_to_scalar );
use YAML ();

my $ffi = FFI::Platypus->new(
  api => 2,
  lib => './xor_cipher.so',
);

$ffi->attach( string_crypt_free => ['opaque'] );

$ffi->attach( string_crypt => ['string','int','string'] => 'opaque' => sub{
  my($xsub, $input, $key) = @_;
  my $ptr = $xsub->($input, length($input), $key);
  my $output = buffer_to_scalar $ptr, length($input);
  string_crypt_free($ptr);
  return $output;
});

my $orig = "hello world";
my $key  = "foobar";

print YAML::Dump($orig);
my $encrypted = string_crypt($orig, $key);
print YAML::Dump($encrypted);
my $decrypted = string_crypt($encrypted, $key);
print YAML::Dump($decrypted);