Hello all. I probably have a simple question. I have a program that I have used a while written in visual C++ under windows. It takes a name, email, and item and adds it together then does some calulations on it to generate a 16 digit number that is pretty unique to the string. I cannot really post the code itself out here but here is the issue.

I needed to write a generator for it in perl that could calculate this same number exactly, to run from a webserver. Well I figured this would be a simple task as perl is powerful. So I "ported" the calculations over to a perl script... but, they come out wrong! It seems that the perl script gains +1 each time through which I have narrowed down to seemingly it rounding off the number through each pass and slowly creeping or drifting off. Now it could be the opposite... maybe the windows app is drifting off. But the windows app has reliably reproduced the same 16 digit number on hundreds of machines and has been in use a good while so we need perl to match the output.

Basically it would work like this looping through and then format the number into a serial at the bottom.

my $seed = "$name$email$item"; while ($seed =~/(.)/g) { $n += 1; if (uc($1) eq uc('a')) { $i = ($i + 173); } # many many lines and calulations here } my $m=sprintf("%.f",$i) ; my $trimmedNumber = substr($m, -16, 16); # trim 16 from the right. printf ("Trimmed: $trimmedNumber\n");
Seed: blabla # would loop through 6 times. Once per character.

Windows app: 2500202166709743

Perl app: 2500202166709760

There are a lot of things here. One was written and run on windows with c++, the other is written and run on linux in perl. The c++ cannot be changed as it has been in use a good while. Can I make perl cooperate or should I just stop now?


In reply to The 16 digit number dilemma. by docster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.