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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |