P
Piotr Turkowski
Hi!
I've got some code in Perl and I have to have it in C, but my knowlege
of Perl is < 0 :-(, so I need your help. here's the code. Thanks in advance.
decrypt.pl
#!/usr/local/bin/perl
$keyword=$ARGV[0] ;
@key=split(//,$keyword) ;
$period=length($keyword) ;
$count=0 ;
while(<STDIN>) {
chop ;
tr/a-z/A-Z/ ;
tr/A-Z//cd ;
@line=split(//) ;
foreach $i (@line) {
$cipher=ord($i)-ord($key[$count % $period])+65;
if ($cipher<65) {$cipher+=26 ; }
print pack("C",$cipher) ;
$count+=1 ;
if ($count % 5 == 0) {print " ";}
}
print "\n" ;
}
print "\n" ;
and encrypt.pl
#!/usr/local/bin/perl
$keyword=$ARGV[0] ;
$keyword=~tr/a-z/A-Z/ ;
@key=split(//,$keyword) ;
$period=length($keyword) ;
$count=0 ;
while(<STDIN>) {
chop ;
tr/a-z/A-Z/ ;
tr/A-Z//cd ;
@line=split(//) ;
foreach $i (@line) {
$cipher=ord($i)+ord($key[$count % $period])-65;
if ($cipher>=91) {$cipher-=26 ; }
print pack("C",$cipher) ;
$count+=1 ;
if ($count % 5 == 0) {print " ";}
if ($count %60 == 0) {print "\n" ; }
}
}
print "\n" ;
I've got some code in Perl and I have to have it in C, but my knowlege
of Perl is < 0 :-(, so I need your help. here's the code. Thanks in advance.
decrypt.pl
#!/usr/local/bin/perl
$keyword=$ARGV[0] ;
@key=split(//,$keyword) ;
$period=length($keyword) ;
$count=0 ;
while(<STDIN>) {
chop ;
tr/a-z/A-Z/ ;
tr/A-Z//cd ;
@line=split(//) ;
foreach $i (@line) {
$cipher=ord($i)-ord($key[$count % $period])+65;
if ($cipher<65) {$cipher+=26 ; }
print pack("C",$cipher) ;
$count+=1 ;
if ($count % 5 == 0) {print " ";}
}
print "\n" ;
}
print "\n" ;
and encrypt.pl
#!/usr/local/bin/perl
$keyword=$ARGV[0] ;
$keyword=~tr/a-z/A-Z/ ;
@key=split(//,$keyword) ;
$period=length($keyword) ;
$count=0 ;
while(<STDIN>) {
chop ;
tr/a-z/A-Z/ ;
tr/A-Z//cd ;
@line=split(//) ;
foreach $i (@line) {
$cipher=ord($i)+ord($key[$count % $period])-65;
if ($cipher>=91) {$cipher-=26 ; }
print pack("C",$cipher) ;
$count+=1 ;
if ($count % 5 == 0) {print " ";}
if ($count %60 == 0) {print "\n" ; }
}
}
print "\n" ;