View Single Post
Old Thu, Jan-31-2013, 08:03:51 AM   #1577
p0lar
Naturally Agitated
 
p0lar's Avatar
 
Join Date: Sep 2005
Posts: 3,554
In the garage:
Reputation: 0 p0lar will become famous soon enough

United States




Default Re: Comprehensive MSS54/MSS54HP DME Information

Perl handles it comfortably, here's proof:

Code:
#!/usr/bin/perl -w

#    Copyright (c) 2012, 2013 p0lar @ m3forum.net
#
#    Redistribution and use in source and binary forms, with or without
#    modification, are permitted provided that the following conditions
#    are met:
#    1. Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#    2. Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#    3. All advertising materials mentioning features or use of this software
#       must display the following acknowledgement:
#	This product includes software developed by p0lar @ m3forum.net and its
#       contributors
#    4. Neither the name of p0lar @ m3forum.net nor the names of its
#       contributors may be used to endorse or promote products derived from
#       this software without specific prior written permission.
#
#    THIS SOFTWARE IS PROVIDED BY P0LAR @ M3FORUM.NET AND CONTRIBUTORS ``AS IS''
#    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#    ARE DISCLAIMED.  IN NO EVENT SHALL P0LAR @ M3FORUM.NET OR CONTRIBUTORS BE
#    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#    POSSIBILITY OF SUCH DAMAGE.
#
#    NO WARRANTY
#
#    BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
#    FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
#    OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
#    PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
#    OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
#    TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
#    PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
#    REPAIR OR CORRECTION.
#
#    IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
#    WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
#    REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
#    INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
#    OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
#    TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
#    YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
#    PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
#    POSSIBILITY OF SUCH DAMAGES.
#

use strict;
use bigint;
use File::Basename;
use Data::Dumper; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1;
use Getopt::Long;

my %config = (
  'help'    => 0,
  'debug'   => 0,
  'version' => '0.0.8',
);

# handle command line options
&GetOptions(
  'help|?|h'    => \$config{'help'},
  'input|i=s'   => \$config{'VIN_input'},
  'debug|d'     => \$config{'debug'},
  'version|v'   => \$config{'displayVersion'},
);

# Display version or usage information if requested (or implicitly)
&usage if ($config{'help'});
&usage unless (defined($config{'VIN_input'}));
&version if (defined($config{'displayVersion'}));

# Check to see if the binary actually exists, is readable, is binary and is of the proper size
die ("No input VIN specified.\n") unless (defined($config{'VIN_input'}));
die ("Wrong length to be VIN.\n") unless (length($config{'VIN_input'}) == 17);

my (%charArr, $num);

# generate character array
for my $j (0..9, "A".."Z") { $charArr{$j} = keys(%charArr) }

# And a simple one-liner that works all the magic..
for (my $i = 1; $i <= length($config{'VIN_input'}); $i++) { $num += $charArr{substr(uc($config{'VIN_input'}), -$i, 1)} * 0x40**($i-1) }

#output
print ($config{'VIN_input'} . " => " . &formathex(substr(uc($num->as_hex), 2)) . "\n");


#----------------------------
# SUBROUTINES               |
#----------------------------

# simple usage/syntax
sub usage {
  print("\nUsage: " . &fileparse($0, qr/\.[%.]*/) . " --input={VIN} --help --debug --version \n\n");
  exit (1);
}

# display version, then exit.
sub version {
  print (&fileparse($0, qr/\.[%.]*/) . " v" . $config{'version'} . "\n");
  exit (0);
}

# simple debug function
sub debug ($) {
  print (@_) if $config{'debug'};
}

# Make the hex output more readable
sub formathex($) {
  my $hexStr = shift();
  my $formatted;
  foreach (my $key = 0; $key < length($hexStr); $key++) {
    $formatted .= (substr($hexStr, $key, 2) . ' ') unless ($key % 2);
  }
  return ($formatted);
}
Code:
bmb:dev p0lar$ ./calcvin.pl -i=Wbsbl93494pn44545
Wbsbl93494pn44545 => 20 2D C2 D5 24 31 09 11 95 C4 10 51 05
Fun over for now! Whose turn is it to throw up a routine that calculates from binary to VIN?

Last edited by p0lar; Thu, Apr-11-2013 at 02:16:42 PM.
Jump to top p0lar is offline   Reply With Quote