Created
September 9, 2009 13:55
-
-
Save malcom/183728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# | |
# o2cfg.pl - Enkoder/dekoder plikow konfiguracyjnych komunikatora Tlen.pl | |
# Copyright (c) 2007 Marcin 'MalCom' Malich <me@malcom.pl> | |
# Licencja GPL | |
# | |
# http://docs.malcom.pl/tlen/cfgfiles.xhtml | |
# http://projects.malcom.pl/scripts/tlen/o2cfg.xhtml | |
# | |
# 2007-08-21 12:20:37 | |
use strict; | |
use Getopt::Std; | |
my(%a,$FS,$FD); | |
my($m)=($0=~m,([^/\\]+)$,); | |
getopts('edi:', \%a); | |
&HELP_MESSAGE and exit if(!$a{e}&&!$a{d}||!$ARGV[0]); | |
$a{e}||=!$a{d}; | |
open $FS,$ARGV[0] or die "Source file: $!"; | |
open $FD,'>'.($ARGV[1]||$ARGV[0].'.out') or die "Destination file: $!"; | |
binmode $a{e}?$FD:$FS; | |
$a{i}||=$a{e}?int(rand 65535)+1:ord(getc $FS)+256*ord(getc $FS); | |
$a{e}?print $FD pack('S',$a{i}):seek $FS,2,0; | |
my $v=($a{e}?-s $FS:(-s $FS)-2)%256; | |
while($a{i}--){$v=(133*$v+231)%256} | |
while(!eof $FS){print $FD chr(ord(getc $FS)^($v=(133*$v+231)%256))} | |
close $FS; | |
close $FD; | |
sub HELP_MESSAGE{print <<EOH; | |
Enkoder/dekoder plikow konfiguracyjnych komunikatora Tlen.pl | |
$m [-e] [-d] [-i iterate] file_source [file_destination] | |
-e koduje plik zrodlowy, wynik zapisuje w pliku docelowym | |
-d dekoduje plik zrodlowy, wynik zapisuje w pliku docelowym | |
-i iterate ilosc iteracji przeksztalcen wartosci poczatkowej wektora, | |
liczba z przedzialu 0-65535, domyslnie dla kodowania wartosc | |
losowa, dla dekodowania wartosc odczytana z pliku | |
file_source plik zrodlowy | |
file_destination plik docelowy, domyslnie file_source.out | |
Wiecej informacji: http://docs.malcom.pl/tlen/cfgfiles.xhtml | |
Strona projektu: http://projects.malcom.pl/scripts/tlen/o2cfg.xhtml | |
EOH | |
} | |
sub VERSION_MESSAGE{print "$m v0.2 (c) 2007 MalCom [ http://malcom.pl ]\n"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment