Warning: opendir(/var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/sh/3.0.83.2/scripts/): failed to open dir: No such file or directory in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 26

Warning: Invalid argument supplied for foreach() in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 170
Skip to content

Perl - xortool

Heute hab ich in Perl ein kleines Tool geschrieben, mit welchem man eine Datei bzw. deren Inhalt zeichenweise XOR verschlüsseln kann.
 
Dazu übergibt man dem Tool die Originaldatei, Zieldatei und natürlich den Schlüssel. Nun wendet das Tool das erste Zeichen des Schlüssels auf das erste Zeichen der Originaldatei an, danach das zweite Zeichen des Schlüssels auf das zweite Zeichen der Datei usw. 
 
Verschlüsselung
 
./xortool originaldatei.txt verschlüsseltedatei.txt 1234
 
Entschlüsselung
 
./xortool verschlüsseltedatei.txt unverschlüsseltedatei.txt 1234
 
Hier der Code:
#!/usr/bin/perl
use strict;
use File::
stat;
 
my $file = $ARGV[0];
my $newfile = $ARGV[1];
my $key = $ARGV[2];
 
if ($#ARGV != 2) {
print "usage: xortool file1 file2 keyn";
exit 1;
}
 
# Filesize
my $filesize =
stat($file)->size;
print "+——————————————+n";
print "Key : ". $key ."n";
print "Key length: ". length($key) ."n";
print "Filesize: $filesizen";
print "+——————————————+n";
 
# open the files
open (my $FILE,"<$file") || die "File not found: $!";
open (my $NEWFILE,">$newfile") || die "No permissions: $!";
 
for (my $i=0;$i<$filesize;$i+=
length($key)) {
 
# seek FILEHANDLE,POSITION,WHENCE
# http://perldoc.perl.org/functions/seek.html
seek($FILE,$i,0);
 
# read FILEHANDLE,SCALAR,LENGTH
# http://perldoc.perl.org/functions/read.html
read($FILE,my $character,length($key));
 
for (my $c=0;$c<=
length($key);$c++) {
# XOR
my $xor =
substr($key,$c,1)^substr($character,$c,1);
print $NEWFILE $xor;
}
}
# close the files
close $FILE;
close $NEWFILE;
#EOF
 
Hier der Link zum Dokuwiki: Klick

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA 1CAPTCHA 2CAPTCHA 3CAPTCHA 4CAPTCHA 5


Textile-formatting allowed
You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Form options
Imprint | Contact | Privacy Statement

Warning: opendir(/var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/sh/3.0.83.2/scripts/): failed to open dir: No such file or directory in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 26

Warning: Invalid argument supplied for foreach() in /var/www/html/web1/serendipity/plugins/serendipity_event_dpsyntaxhighlighter/serendipity_event_dpsyntaxhighlighter.php on line 170