#!/usr/bin/perl

# MPEG 2 PS VOB file on stdin -> descrambled output on stdout
# arguments: title key bytes in least to most-significant order

# perl -I xx:xx:xx:xx:xx cp5qrpff-fast.pl < file.vob | extract_mpeg2 | mpeg2dec
# where xx:xx:xx:xx:xx is the title key

s''while(read+STDIN,_,2048){Q=29;O=73;J=142;P=255;@t=map{_%16orP^=J^=(Y
=(11,10,116,100,11,122,20,100)[_/16%8])&110;P^=(72,@z=(64,72,Q^=12*(_%
16-2?0:Y&17)),O^=_%64?12:0,@z)[_%8]}(16..271);if((@a=unx"C*",_)[20]&48){
X=5;_=unxb24,join"",@b=map{xB8,unxb8,chr(_^$a[--X+84])}@ARGV;s/...$/1$&/;
K=unxV,xb25,_;L=256|(ord$b[4])<<9|ord$b[3];K=K>>8^(M=P&(K>>12^K>>4^K^K/8
))<<17,L=L>>8^(P&(W=(Z=L>>14&7^L)^Z*8^Z<<6))<<9,_=$t[_]^((X>>=8)+=M+(~W&P
))for@a[128..$#a]}print+x"C*",@a}';s/x/pack+/g;s/[O-QJ-MW-Z_]/\$$&/g;eval
