Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
marcus.hardt
pluto
Commits
ff7bb145
Commit
ff7bb145
authored
Oct 15, 2014
by
marcus-tun
Browse files
added short perl example
parent
a6f77a1f
Changes
1
Hide whitespace changes
Inline
Side-by-side
interop/pl/interop.pl
0 → 100755
View file @
ff7bb145
#!/usr/bin/env perl
use
strict
;
use
Getopt::
Long
qw(:config bundling)
;
use
Crypt::
CBC
;
my
%opts
=
();
my
$verbose
=
0
;
my
$iv
=
'
0000000000000000
';
my
$key
=
'
0000000000000000
';
my
$plaintext
=
'
hello world, today is a good day to have long strings
';
# Get options
GetOptions
(
\
%opts
,
'
help|h
',
'
verbose|v
',
'
iv|i=s
',
'
key|k=s
',
'
plaintext|p=s
',
)
or
exit
;
if
(
exists
$opts
{
help
})
{
print
("
Usage: interop.pl [arguments]
-v, --verbose
-i, --iv
-k, --key
-p, --plaintext
\n
");
exit
(
0
);
}
if
(
exists
$opts
{
verbose
})
{
$verbose
=
1
;
}
if
(
exists
$opts
{
iv
})
{
$iv
=
trim
(
$opts
{
iv
});
}
if
(
exists
$opts
{
key
})
{
$key
=
trim
(
$opts
{
key
});
}
if
(
exists
$opts
{
plaintext
})
{
$plaintext
=
trim
(
$opts
{
plaintext
});
}
## Debug output
print
("
plaintext:
"
.
$plaintext
.
"
\n
")
if
$verbose
;
print
("
iv:
"
.
$iv
.
"
\n
")
if
$verbose
;
print
("
key:
"
.
$key
.
"
\n
")
if
$verbose
;
## ENCRYPTION
my
$encryption_algorithm
=
'
Rijndael
';
my
$cipher
=
new
Crypt::
CBC
(
$key
,
$encryption_algorithm
,
-
iv
=>
$iv
,
-
header
=>
'
none
');
my
$ciphertext
=
$cipher
->
encrypt
(
$plaintext
);
my
$perl_iv
=
$cipher
->
iv
();
#my $perl_pass = unpack('H*', $cipher->key());
my
$perl_pass
=
$cipher
->
key
();
print
('
perl_iv:
'
.
$perl_iv
.
"
\n
")
if
$verbose
;
print
('
perl_pass:
'
.
$perl_pass
.
"
\n
")
if
$verbose
;
print
("
\n
");
## DECRYPTION
my
$de_cipher
=
new
Crypt::
CBC
(
$key
,
$encryption_algorithm
,
-
iv
=>
$iv
,
-
header
=>
'
asdf
');
my
$new_plaintext
=
$de_cipher
->
decrypt
(
$ciphertext
);
print
("
decrypted:
"
.
$new_plaintext
.
"
\n
")
if
$verbose
;
print
("
worked
\n
")
if
(
$plaintext
eq
$new_plaintext
);
#########################################################################
# subroutine: trim($str) #
# parameter : $str - a string to trim spaces from. #
# returns : the passed-in string with leading and trailing spaces #
# removed. #
# this subroutine removes leading and trailing spaces from the #
# passed-in string. note that the original string is not modified. #
# rather, a new string without leading/trailing spaces is returned. #
#########################################################################
sub
trim
{
my
$str
=
shift
;
$str
=~
s/^\s+//
;
$str
=~
s/\s+$//
;
return
$str
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment