| Catenation Limit for a Decoding/Encoding program 
 
	 
	
		| Author | Message |   
		| heero138 
 
 
 
 
 | 
			
				|  Posted: Wed Nov 08, 2006 11:09 am    Post subject: Catenation Limit for a Decoding/Encoding program |  |   
				| 
 |  
				| This program uses run with args to read a text file and decode or encode it. So the program works fine except my teacher wants it to work for any number of words but this program will only work for the text file I'll post after the source code
 
 
 military.t wrote: 
%Military Coding Program
 %This is a military coding program that decodes or encodes depending on
 %on the key word at the header, if the key word is hi123 then it encodes
 %if the word is 321ih then it decodes and if the keyword is not present then
 %it does nothing
 %Declared variables
 var key, word, message : string
 var blankStop : int := 0
 %Sets "message" to an empty string
 message := ""
 loop
 %Locates the key word which will decide whether or not the program will decode, encode
 %or do nothing at all
 get key
 %If the keyword is hi123 then it encodes the message
 if index (key, "hi123") not= 0 then
 %Outputs the new headers
 put "Decode + 4"
 put "321ih"
 put ""
 loop
 %Exits when end of file
 exit when eof
 %Puts the blank to seperate words
 message := " " + message
 get word
 %If the word is not the key word then it is spelt backwards
 if word not= "hi123" then
 %Runs through each letter of the word changing it by subtracting 4 to the ASCII code
 for m : 1 .. length (word)
 message := chr (ord (word (m)) - 4) + message
 end for
 else
 %If the current word is the key word it is spelt backwards but not encoded
 key := ""
 for m : 1 .. length (word)
 key := word (m) + key
 end for
 message := key + message
 end if
 end loop
 %Outputs encoded message
 put message
 exit
 %If the key word is backwards ("321ih") then it decodes
 elsif index (key, "321ih") not= 0 then
 %Outputs the new header
 put "Encode - 4"
 put "hi123"
 put ""
 loop
 %Exits when end of file
 exit when eof
 %Puts the blank to seperate words
 message := " " + message
 get word
 %If the word is not the keyword then it is spelt backwards (it's original spelling)
 if word not= "321ih" then
 %Runs through each letter of the word changing it by adding 4 to the ASCII code
 for m : 1 .. length (word)
 message := chr (ord (word (m)) + 4) + message
 end for
 %If the word is the key word then it is unchanged.
 else
 %If the current word is the key word it is put back to it's original positioning
 key := ""
 for m : 1 .. length (word)
 key := word (m) + key
 end for
 message := key + message
 end if
 end loop
 %Outputs decoded message
 put message
 exit
 end if
 end loop
 
 
 
 text file wrote: 
Encode - 4
 hi123
 
 The nuclear warheads are about to be delivered hi123
 be prepared to pick them up at hi123 23:00 at the docks hi123
 Also here is the report from the spies in Canada
 Troops are moving towards hi123 the western front hi123
 PM Joey Mcman hi123 has been KIA  %
 
 If I add even 1 character to that text file the string catenation is too long o_o
 
 I'm stumped >_> if I add 1 more character to that it still works for my teachers program but not on mine
 
 Anyone know whats the problem with my source code? o_O
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| rdrake 
 
  
 
 
 | 
			
				|  Posted: Wed Nov 08, 2006 12:14 pm    Post subject: Re: Catenation Limit for a Decoding/Encoding program |  |   
				| 
 |  
				| heero138 wrote: Anyone know whats the problem with my source code? o_OProblem is you're using the [ quote] [/quote ] tags instead of the proper [ code][/code ] tags. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| heero138 
 
 
 
 
 | 
			
				|  Posted: Wed Nov 08, 2006 8:06 pm    Post subject: (No subject) |  |   
				| 
 |  
				| ah my fault here it is again then. Sorry I didn't notice the "code" thing =O and I didn't seem to bother because most places I just quote it XD
 
 
 	  | code: |  	  | 
%Military Coding Program
 %This is a military coding program that decodes or encodes depending on
 %on the key word at the header, if the key word is hi123 then it encodes
 %if the word is 321ih then it decodes and if the keyword is not present then
 %it does nothing
 %Declared variables
 var key, word, message : string
 var blankStop : int := 0
 %Sets "message" to an empty string
 message := ""
 loop
 %Locates the key word which will decide whether or not the program will decode, encode
 %or do nothing at all
 get key
 %If the keyword is hi123 then it encodes the message
 if index (key, "hi123") not= 0 then
 %Outputs the new headers
 put "Decode + 4"
 put "321ih"
 put ""
 loop
 %Exits when end of file
 exit when eof
 %Puts the blank to seperate words
 message := " " + message
 get word
 %If the word is not the key word then it is spelt backwards
 if word not= "hi123" then
 %Runs through each letter of the word changing it by subtracting 4 to the ASCII code
 for m : 1 .. length (word)
 message := chr (ord (word (m)) - 4) + message
 end for
 else
 %If the current word is the key word it is spelt backwards but not encoded
 key := ""
 for m : 1 .. length (word)
 key := word (m) + key
 end for
 message := key + message
 end if
 end loop
 %Outputs encoded message
 put message
 exit
 %If the key word is backwards ("321ih") then it decodes
 elsif index (key, "321ih") not= 0 then
 %Outputs the new header
 put "Encode - 4"
 put "hi123"
 put ""
 loop
 %Exits when end of file
 exit when eof
 %Puts the blank to seperate words
 message := " " + message
 get word
 %If the word is not the keyword then it is spelt backwards (it's original spelling)
 if word not= "321ih" then
 %Runs through each letter of the word changing it by adding 4 to the ASCII code
 for m : 1 .. length (word)
 message := chr (ord (word (m)) + 4) + message
 end for
 %If the word is the key word then it is unchanged.
 else
 %If the current word is the key word it is put back to it's original positioning
 key := ""
 for m : 1 .. length (word)
 key := word (m) + key
 end for
 message := key + message
 end if
 end loop
 %Outputs decoded message
 put message
 exit
 end if
 end loop
 | 
 
 anyone possibly know how I would be able to make this work for atleast 100 words? o_O It seems to only go up to 265 characters X_X
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| rdrake 
 
  
 
 
 | 
			
				|  Posted: Wed Nov 08, 2006 8:35 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Evidently you still need to discover the F2 button as well.  Formats your code nice and well for ya. 
 As for the issue, there is a limit to how long of strings Turing can hold.  I think it's actually 255.  Only way I can think of doing this would be to read the text file block by block... but I'm sure there's lots of creative solutions floating around here, just search around.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| jrblast 
 
 
 
 
 | 
			
				|  Posted: Wed Nov 08, 2006 10:17 pm    Post subject: (No subject) |  |   
				| 
 |  
				| does the program have to store it in a variable? or can you just write to a new file directly? if it needs to be output to the screen, you can do that one letter at a time (as you decode it) and then I think turing has a command to read text off the screen, though I could be mistaken. 
 To do it rdrakes way I suggest a flexible array, whenever the string in one element reaches 255 chars (if that is the max) which you can check using the length function which returns the length of a string, then create a new element (a little complicated but better than nothing)
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| DKNiGHTX 
 
  
 
 
 | 
			
				|  Posted: Wed Nov 08, 2006 10:37 pm    Post subject: (No subject) |  |   
				| 
 |  
				| rdrake wrote: Evidently you still need to discover the F2 button as well.  Formats your code nice and well for ya.
 As for the issue, there is a limit to how long of strings Turing can hold.  I think it's actually 255.  Only way I can think of doing this would be to read the text file block by block... but I'm sure there's lots of creative solutions floating around here, just search around.
 
 The computers at my school can't indent code with more than 200 characters in one line.  Memory error
   
 As for the 'creative solution'.  Could you not have a single dimension array, holding strings of 254 or 255 characters in each reference then join them by looping through the values?  I've never encountered a 255 block, however
  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| heero138 
 
 
 
 
 | 
			
				|  Posted: Thu Nov 09, 2006 10:10 am    Post subject: (No subject) |  |   
				| 
 |  
				| thanks for the ideas =D sadly I don't know how to work arrays and so I'll output the letters as they go 
 Can't believe I didn't think of that o_o
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| jrblast 
 
 
 
 
 | 
			
				|  Posted: Thu Nov 09, 2006 8:19 pm    Post subject: (No subject) |  |   
				| 
 |  
				| If you need to learn arrays theres a tutorial in the tut forum, I would link you to it but my internet is taking forever to load any single page. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		|  |  
 |