Failing to compile

closed account (3UkNvCM9)
I've been having issues compiling this coding for 3 days scratching my head to make it into a windows executable. I've been using Dev-C++ to compile and debug but I'm a little lost in the lingo and have been doing the research and troubleshooting online but became confused. Any help is greatly appreciative also this is for personal use not business or for profit.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  use strict;
use bigint;
use Getopt::Long;

use constant {
  DEBUG   => 0,
  HELP    => 0,
  PROGRAM => 'vincoder',
  VERSION => 'v0.1.1',
};

my %config;

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

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

my (%charArr, %numArr);

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

# handle VIN -> binary/hexadecimal
if (defined($config{'VIN_input'})) {
  die ("Wrong length to be text VIN.\n") unless (length($config{'VIN_input'}) == 17);
  die ("Improper characters in VIN.\n") unless ($config{'VIN_input'} =~ /^[0-9A-HJ-NPR-Z]{17}$/i);
  print (uc($config{'VIN_input'}) . ' -> ' . &formathex(uc(&VINtoHex($config{'VIN_input'})->as_hex)) . "\n");
}

# handle binary/hexadecimal -> VIN
if (defined($config{'BIN_input'})) {
  $config{'BIN_input'} =~ s/\s+//g;
  die ("Wrong length to be decimal or hexadecimal VIN.\n") unless (length($config{'BIN_input'}) == 13 || 26);
  die ("Improper hexadecimal characters.\n") unless ($config{'BIN_input'} =~ /^[0-9A-F]{26}$/i);
  print (&formathex(uc($config{'BIN_input'})) . ' -> ' . &hexToVIN('0x' . $config{'BIN_input'}) . "\n");
}

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

# simple usage/syntax
sub usage {
  print("\nUsage: " . PROGRAM . " --vin={VIN} --bin={BINARY/HEX} --help --version\n\n");
  exit (1);
}

# display version, then exit.
sub version {
  print (PROGRAM . ' ' . 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);
  }
  $formatted =~ s/^0x//ig;
  return ($formatted);
}

sub VINtoHex ($) {
  my $VIN = shift();
  my $hex;
  for (my $i = 1; $i <= length($VIN); $i++) {
    $hex += $charArr{substr(uc($VIN), -$i, 1)} * 0x40**($i-1);
  }
  return ($hex);
}

sub hexToVIN ($) {
  my $hex = shift();
  my $VIN;
  my %numArr = reverse(%charArr);
  for (my $i = 0x10; $i >= 0; $i--) {
    my $j = $hex / 0x40**($i);
    $hex -= $j * 0x40**($i);
    $VIN .= ($numArr{$j});
  }
  return (uc($VIN));
}
~ ]$ chmod 755 vincoder

~ ]$ ./vincoder -b=202dc34e24310404b8c9203048
20 2D C3 4E 24 31 04 04 B8 C9 20 30 48  -> WBSDE93441BZ98318

~ ]$ ./vincoder -v=WBSDE93441BZ98318
WBSDE93441BZ98318 -> 20 2D C3 4E 24 31 04 04 B8 C9 20 30 48
What language is that?
It's not C++, I can tell you that much.
closed account (3UkNvCM9)
My buddy helped make this on his Macbook Pro, It decodes vin binary for ECU's we are working on. Now when we were discussing this he stated ii is using a Base64 Encoding mathematics and is best used with a 64-bit bigint module. I noticed some irregularities in reference to C++ coding, doesn't match up. What way can I convert this language to C++?
Unless your buddy is over 40, I doubt he wrote this. It's Perl, which has been pretty much superseded by Python these days. I suspect that you found this code somewhere and want help "translating" it to C++.
Can't your buddy help you install what you need in order to compile and run the program?

If you really want to convert the code to C++ I'm afraid you will have to understand what the program does and know enough C++ to write it.
Last edited on
closed account (3UkNvCM9)
tpb - I never looked up the code I just saw that my buddy was messing around with the code on his Mac, so I assumed he developed it my apologies. Yes I'm looking to translate it to C++ etc. I don't take any credit in building it, but I know tuning aspects so thats why we came to conversation in this. Thanks for the insight because I never even thought to google it.
Last edited on
It's just a perl script that encodes 26-character hex strings as 17-character vehicle identification numbers (VINs). Looks like it also has decode support.

Quick google to debunk your theory that your buddy wrote it himself finds this original-looking post: http://www.m3forum.net/m3forum/archive/index.php/t-465223.html
Last edited on
@icy1, Good find. It would be easy enough to write it in C++. The only thing is that it requires some minimal big integer support.
@tpb, nah, just needs a better algorithm to carefully convert pieces of it, as some of the comments suggest. I did look at one of the commenter's Ruby solution a bit, since I'm fond of that language, but that one returns the wrong stuff.
@icy1, good point. I'm going to look into that.
Topic archived. No new replies allowed.