comp.lang.ada
 help / color / mirror / Atom feed
From: "isaac2004" <isaac_2004@yahoo.com>
Subject: help with string splitting
Date: 8 Mar 2006 16:12:12 -0800
Date: 2006-03-08T16:12:12-08:00	[thread overview]
Message-ID: <1141863131.984654.144550@j52g2000cwj.googlegroups.com> (raw)

hello how would I create an Ada program to take an encrypted string
from a txt file and decrypt it. i have a so so program but it doesnt
work i cant get the algorithm right.

an example is this
Mother would be Mtoehr encrypted

so its just like cutting the string in half and rearranging the
chaacters to fix the decryption

my example uses a txt file which the contents are

encrypted version
aaabbb

real code
ababab

here is the program i have so  far

with Ada.Text_Io;
use Ada.Text_Io;
procedure Assignment_4 is
   ---------------------------------------------------------
   --|This program takes in a railfence encryption and deciphers it
   --|Author: Isaac Levin
   -------------------------------------------------------
   subtype Message is String (1..1024);

   Codedtext : Message;   --input - string of coded text
   Plaintext : Message;   --output - plain text message
   Indata    : File_Type;

   Length : Natural := 1; --total size of the encrypted message
   J      : Integer := 0; --adjusts midpoint for odd and even strings
   K      : Integer := 2; --counter for the encrypted string

begin -- Assingment_4

   --Open the proper text file and read the code into the string
CodedText

   Open(
      File => Indata,
      Mode => In_File,
      Name => "test.txt");

   while not End_Of_File(File => Indata) loop

      Get(
         File => Indata,
         Item => Codedtext (Length));
      Length := Length + 1;

   end loop;

   --Reconfigures the length to account for odd or even string lengths

   if Length REM 2 = 0 then
      J := 0;
   else
      J := 1;
   end if;

   --Stores the first charcter of the coded message into the decoded
one

   if Length > 1 then
      Plaintext(1) := Codedtext(1);
   end if;

   --Stores every character of the encoded string up to the halfway
point
   --into every odd position in the decoded one

   for I in 2..(Length - 1) loop

      if I REM 2 = 0 then
         Plaintext(I + 1) := Codedtext(K);
         K := K + 1;
      else
         null;
      end if;

   end loop;

   K := 1;

   --Stores every character of the encoded string past the halfway
point
   --into every even position in the decoded one

   for I in 2..(Length - 1) loop

      if I REM 2 = 0 then
         Plaintext(I) := Codedtext((Length/2) + J + K);
         K := K + 1;
      else
         null;
      end if;

   end loop;


   --Output the string PlainText to the screen

   for I in 1..(Length - 1) loop

      Put(Item => Plaintext (I));

   end loop;

   Close(File => Indata);

end;

the program just cuts off the last letter in the string. i think this
has something to do with my splitting of even number strings. any help
would be greatly appreciated.

Isaac




             reply	other threads:[~2006-03-09  0:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-09  0:12 isaac2004 [this message]
2006-03-09  0:44 ` help with string splitting jimmaureenrogers
2006-03-09  2:21 ` Jeffrey R. Carter
2006-03-09  5:54   ` isaac2004
2006-03-09 16:50     ` Martin Krischik
2006-03-09 18:31       ` isaac2004
2006-03-09 19:58         ` jimmaureenrogers
2006-03-10 10:45         ` Martin Krischik
2006-03-09 19:28     ` Jeffrey R. Carter
2006-03-09  7:43 ` Anders Wirzenius
2006-03-09 10:15 ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox