Hi Lars,

please reply to all recipients.

On Tue, 02 Jun 2015 12:54:54 +0300
Lars Noodén <lars.noo...@gmail.com> wrote:

> I have a calculated variable $otp which is decrypted using AES key $key.
>  If the variable was properly decrypted, the first six bytes of the
> decrypted data should match what is in $userid, I think.
> 
> How do I extract the first six bytes of $plaintext and compare it to
> what's in $userid ?
> 

To extract the first six bytes, use the substr function:

http://perldoc.perl.org/functions/substr.html

The command «my $first_6_bytes = substr($plaintext, 0, 6);» ought to do the
tricks (but there may be some complications due to Unicode and
charsets/encoding).

To compare it to $userid, you can use "eq", "cmp", etc. See:

http://perldoc.perl.org/perlop.html

It seems that $userid is encoded in hex so you'll need to convert it to a plain
binary string first.

Regards,

        Shlomi Fish

> Regards,
> Lars
> 
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Convert::ModHex qw(modhex2hex);
> use Crypt::Rijndael;
> 
> my $input  = qq(ujvrgjnigiibvrjctcflercebvcvhicbnhhheliclnfh);
> my $key    = qq(83b396b8f996fa1be3dafdc3f0eefc21);
> my $userid = qq(aa6d0a6e8a65);
> 
> my ( $publicid, $otp ) = ( $input =~ /^(.*)(.{32})$/ ); # OTP 32B
> 
> my $hex = modhex2hex($otp);
> print qq(publicid=$publicid\n$otp\n$hex\n\n);
> 
> my $cipher = Crypt::Rijndael->new( $key, Crypt::Rijndael::MODE_CBC() );
> 
> my $plaintext = $cipher->decrypt($hex);
> 
> print qq(\np=$plaintext\n);
> 
> exit( 0 );
> 



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
List of Portability Libraries - http://shlom.in/port-libs

Daniel: Yeah, those guys [= NSA] don’t publish…
Andrew: They perish, man.
    — http://www.shlomifish.org/humour/Summerschool-at-the-NSA/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to