469,575 Members | 1,651 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

[crosspost] Perl -> C

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" ;

--
Best Regards
Piotr Turkowski
Jul 19 '05 #1
4 2408
"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
news:bv**********@nemesis.news.tpi.pl...
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


[snip code]

Well, Perl's OT in c.l.c., and C's OT in c.l.p., so
what's a body to do?? :-)

I suggest you ask someone in the Perl group to explain
in English what the Perl code does, then you can write
the C code from the English specification. If you get
stuck, post the functional description to the C group
along with your code, and we can offer ideas and suggestions,
etc.

HTH,
-Mike
Jul 19 '05 #2
Użytkownik Mike Wahler napisał:
Well, Perl's OT in c.l.c., and C's OT in c.l.p., so
what's a body to do?? :-)
And this is the very true truth :) (sorry for my Engilsh ;-)
I suggest you ask someone in the Perl group to explain
in English what the Perl code does, then you can write
the C code from the English specification. If you get
stuck, post the functional description to the C group
along with your code, and we can offer ideas and suggestions,
etc.


OK, so here is what i want to create.
1. Text editor with GUI, which would have an opportunity to
encypt/decrypt text with Vigerene Cipher.
2. Options: saving/opening files :)
3. New file type: *.vig (encrypted file)
4. Two langauge program (polish/english) I can translate it :D
5. Changing font, size of text, just for display (you know what i mean)
*6. Registration form. Shareware, or sth. Someone send me his 'name' i
generate 'key' and then program is fully functionally. If not, the
program can encrypt/decrypt only 20 chars, and can't save and open
encrypted file.

*at the end
So, I'm a real noob. I don't want you to write this program, I just need
your help :). So guide me, what I shuold create at the beggining. Mayby
some examples of text editor ?

best regards
Peter
Jul 19 '05 #3

On Sun, 25 Jan 2004, Piotr Turkowski wrote in comp.lang.c:

Użytkownik Mike Wahler napisał:
I suggest you ask someone in the Perl group to explain
in English what the Perl code does, then you can write
the C code from the English specification. If you get
stuck, post the functional description to the C group
along with your code, and we can offer ideas and suggestions,
etc.
OK, so here is what i want to create.
1. Text editor with GUI, which would have an opportunity to
encypt/decrypt text with Vigerene Cipher.


Writing full-screen editors or other GUIs is off-topic in this
newsgroup, where we discuss standard C only. Standard C has no
support for GUIs or screen manipulation. (And probably off-topic
in comp.lang.perl, too, but I don't read that group.)
As for Vigenere solvers, you can search Google or Google Groups
for C source code. J.W. Stumpel wrote some decent Vigenere code
a while back, for instance. Given an encrypted text, it returns
its best guess as to the key and the original plaintext. If you
want help *writing* a Vigenere program, ask in comp.programming
or sci.crypt. If you want help *understanding* Stumpel's code,
or anyone else's C code, *then* c.l.c will be happy to help you.
2. Options: saving/opening files :)
This is topical here; look up 'fopen' and 'fprintf' in the
standard C library.
3. New file type: *.vig (encrypted file)
Most operating systems let you call your files whatever you
want. The details of your particular OS are off-topic in
comp.lang.c, which discusses a programming language, not an OS.
4. Two langauge program (polish/english) I can translate it :D
Polish, as it uses a different alphabet (and one not actually
guaranteed to get much support from the C language), might require
a bit of work. But not too much.
5. Changing font, size of text, just for display (you know what i mean)
Not really. "Font" in a program that deals with encryption and
decryption of text? What possible use could that serve?
*6. Registration form. Shareware, or sth. Someone send me his 'name' i
generate 'key' and then program is fully functionally. If not, the
program can encrypt/decrypt only 20 chars, and can't save and open
encrypted file.
IMNSHO, if you can't write your program on your own, without coming
to Usenet for spoon-feeding, you don't deserve to get any money for
the final product (as it won't be *yours*, but belong to whoever
actually wrote the relevant code in the first place). Anyway,
philosophical objections aside, nobody is going to pay for a program
they can get for free anyway, unless you're planning to sell technical
support for the Vigenere cipher. :-D
So, I'm a real noob. I don't want you to write this program, I just need
your help :). So guide me, what I shuold create at the beggining. Mayby
some examples of text editor ?


pico, vim, emacs. In fact, although it's off-topic here, I bet
there's a way to add a "mod" to emacs so that it can do Vigenere
ciphering on its own. I'm sure a Polish version of emacs already
exists, probably even with a spell-checker and all those bells and
whistles. Try a group devoted to emacs (possibly in the gnu.*
hierarchy?).

-Arthur

Jul 19 '05 #4
Mike Wahler wrote:
"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
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.


[snip code]

Well, Perl's OT in c.l.c., and C's OT in c.l.p., so
what's a body to do?? :-)


Maybe go somewhere more tolerant, such as comp.programming.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

31 posts views Thread by surfunbear | last post: by
reply views Thread by Kirt Loki Dankmyer | last post: by
97 posts views Thread by xahlee | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.