This Inline C widget will do it. It modifies the passed SV C style if it is suitable for decryption, or ignores it if the magic header is missing.

use Inline C; my $password = "hello"; my $file = "c:/enc.txt"; open F, $file or die $!; my $data = do{ local $/; <F> }; close F; print "Before:\n$data\n"; decode( $data, $password ); print "After:\n$data\n"; __END__ __C__ typedef unsigned int ULG; void decode( SV* str, char *passwd ) { ULG s,t,v,crc_32_tab[256],keys[3],temp; STRLEN rawlen; int decrypted = 0; char *file, *data; char *magic = "VimCrypt~01!\0"; #define ROTOR(a) { \ keys[0] = CRC32(keys[0], a); keys[1] += keys[0] & 0xff; \ keys[1] = keys[1] * 134775813L + 1; \ keys[2] = CRC32(keys[2], (int)(keys[1] >> 24)); \ } #define CRC32(c, b) (crc_32_tab[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8)) file = (char*)SvPV(str, rawlen); if ( rawlen == 0 ) return; /* we got a null string */ while ( *magic != '\0' ) { if ( *(magic++) != *(file++) ) return; /* did not find magic h +eader */ } for (t=0; t<256; t++) { v = t; for (s=0; s<8; s++) v = (v >> 1) ^ ((v & 1) * (ULG)0xedb88320L +); crc_32_tab[t] = v; } keys[0] = 305419896L; keys[1] = 591751049L; keys[2] = 878082192L; while (*passwd != '\0') ROTOR(*(passwd++)); data = file; while( *file != '\0' ) { temp = 0xffff & (keys[2] | 2); *file ^= (int)(((temp * (temp ^ 1)) >> 8) & 0xff); ROTOR(*(file++)); decrypted++; } sv_setpvn( str, data, decrypted ); /* modify the passed SV with de +crypt */ }

cheers

tachyon


In reply to Re: 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.