Loading ...
Sorry, an error occurred while loading the content.

pls help on a simple problem

Expand Messages
  • anthonyjohn_3
    Hi I have a proj like this:· Encoder-Decoder Given a sentence written in English, this application should be able to encrypt and decrypt the sentence by
    Message 1 of 2 , Nov 30, 2002
    • 0 Attachment
      Hi I have a proj like this:·
      Encoder-Decoder
      Given a sentence written in English, this application should be able
      to encrypt and decrypt the sentence by simply substituting different
      characters for every English character. The original input string is
      called the clear text. When encrypted, this clear text is now called
      the cipher. The program reads from a text file the code translation
      table. This table describes what character is to be used to
      substitute for the character in the clear text.

      Given the code translation table (input from a file):
      a = % g = | m = ~ s = 3 y = 0
      b = & h = \ n = " t = 4 z = #
      c = ) i = ^ o = ` u = 5 space = -
      d = * j = > p = : v = 6
      e = $ k = < q = ; w = 9
      f = + l = ? r = _ x = 8

      User Input: hello world ß clear text

      Encoded: \$??'-9'_?* ß cipher
      Decoded: hello world


      Now I have code like this:

      #!/usr/local/bin/perl

      print ("-:|:-Simple Coder-Decoder Program-:|:-\n");

      $inputline =<STDIN>;
      chop($inputline);


      #$first_byte = substr($inputline, 0, 1);
      #print ($first_byte);

      $file = 'decode.txt' ; # Name the file
      open(INFO, "<$file" ) ; # Open the file
      @lines = <INFO> ; # Read it into an array
      close(INFO) ; # Close the file



      for ( $i=1; $i<(length($inputline)+1); $i++ )
      {
      foreach $lines (@lines)
      {
      #print ($lines);
      $third_char=substr($lines, 0, 3);
      $first_char=substr($lines, 0, 1);
      if($first_char==substr($inputline, 0, $i))
      {
      print (\n$third_char);
      }
      }
      }

      wonder why always got an error cant locate object method n via
      package a=% at perl.txt line 28. How will I manipulate each line of
      text to $lines? or how I convert it to a string?

      the decoder.txt contains like this:
      a=%
      b=&
      c=)
      d=*
      e=$
      f=+
      g=|
      h=\
      i=^
      j=>
      k=<
      l=?
      m=~
      n="
      o='
      p=:
      q=;
      r=_
      s=3
      t=4
      u=5
      v=6
      w=9
      x=8
      y=0
      z=#
      =-
    • Charles K. Clarkson
      ... print n$third_char ; ... HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328
      Message 2 of 2 , Nov 30, 2002
      • 0 Attachment
        anthonyjohn_3 [anthonyjohn_3@...] wrote:

        : for ( $i=1; $i<(length($inputline)+1); $i++ )
        : {
        : foreach $lines (@lines)
        : {
        : #print ($lines);
        : $third_char=substr($lines, 0, 3);
        : $first_char=substr($lines, 0, 1);
        : if($first_char==substr($inputline, 0, $i))
        : {
        : print (\n$third_char);

        print "\n$third_char";

        : }
        : }
        : }

        HTH,

        Charles K. Clarkson
        --
        Head Bottle Washer,
        Clarkson Energy Homes, Inc.
        Mobile Home Specialists
        254 968-8328
      Your message has been successfully submitted and would be delivered to recipients shortly.