[crosspost] Perl -> C

Discussion in 'Perl' started by Piotr Turkowski, Jan 25, 2004.

  1. 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
     
    Piotr Turkowski, Jan 25, 2004
    #1
    1. Advertising

  2. Piotr Turkowski

    Mike Wahler Guest

    "Piotr Turkowski" <> wrote in message
    news:bv12to$hef$...
    > 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
     
    Mike Wahler, Jan 25, 2004
    #2
    1. Advertising

  3. 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
     
    Piotr Turkowski, Jan 25, 2004
    #3
  4. 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
     
    Arthur J. O'Dwyer, Jan 25, 2004
    #4
  5. Piotr Turkowski

    CBFalconer Guest

    Mike Wahler wrote:
    > "Piotr Turkowski" <> 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 () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Jan 26, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anon
    Replies:
    6
    Views:
    521
  2. Piotr Turkowski

    [crosspost] Perl -> C

    Piotr Turkowski, Jan 25, 2004, in forum: C Programming
    Replies:
    7
    Views:
    754
    Dave Thompson
    Feb 9, 2004
  3. Kurciok
    Replies:
    0
    Views:
    362
    Kurciok
    Aug 16, 2006
  4. Michael Reichenbach
    Replies:
    5
    Views:
    3,364
    grahamaaron
    Feb 8, 2010
  5. Star Cross

    A crosspost from the Perl Community

    Star Cross, Jun 4, 2008, in forum: Ruby
    Replies:
    54
    Views:
    453
    Marc Heiler
    Jun 22, 2008
Loading...

Share This Page