Can this be done as a Perl subroutine rather than an Inline C widget ?

Yes

Are there advantages in doing it via Inline C ?

Yes. The actual Vim code is C so all I did was rip the required code out of Vim and drop it into Inline C. Actually I could not resist cleaning it up a bit but that's another story. Add the fact that C is much faster than doing it in Perl, it is now done in C/XS and I have no desire to port it to Perl just so it can be slower.

Porting is fairly easy, but not trivial. The thing that makes it non trivial is that most encryption code utilises the natural rollover of integer types. Things get a bit odd in Perl in a DWIM sort of way which is not identical to C - as a result you need to know how to fix those issues.

use Inline 'C'; use constant UNSIGNED_MAX => 2**32-1; printf "Perl: %u\t%s\n", UNSIGNED_MAX, UNSIGNED_MAX; printf "Perl: %u\t%s\n", (UNSIGNED_MAX+1),(UNSIGNED_MAX+1); printf "Perl: %u\t%s\n", (UNSIGNED_MAX+2),(UNSIGNED_MAX+2); func( UNSIGNED_MAX ); __END__ __C__ int func( unsigned int arg ) { printf( "C: %u\n", arg ); printf( "C: %u\n", arg+1 ); printf( "C: %u\n", arg+2 ); return 0; }

This shows you the main issue:

Perl: 4294967295 4294967296 Perl: 4294967295 4294967297 Perl: 4294967295 4294967298 C: 4294967295 C: 0 C: 1

As you can see C and Perl produce different results at the rollover point.

cheers

tachyon


In reply to Re^3: How to decrypt a file encrypted with vi -x or shell crypt by tachyon
in thread How to decrypt a file encrypted with vi -x or shell crypt by rinceWind

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.