From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c8faa961aaf3fddb,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!j52g2000cwj.googlegroups.com!not-for-mail From: "isaac2004" Newsgroups: comp.lang.ada Subject: help with string splitting Date: 8 Mar 2006 16:12:12 -0800 Organization: http://groups.google.com Message-ID: <1141863131.984654.144550@j52g2000cwj.googlegroups.com> NNTP-Posting-Host: 67.170.5.168 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1141863137 4795 127.0.0.1 (9 Mar 2006 00:12:17 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 9 Mar 2006 00:12:17 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: j52g2000cwj.googlegroups.com; posting-host=67.170.5.168; posting-account=bWy1LAwAAAAtVkasDCH0ykMCBMNd-FcL Xref: g2news1.google.com comp.lang.ada:3297 Date: 2006-03-08T16:12:12-08:00 List-Id: 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