Hi there folks! I would like to have a programme that can encipher a text read out of a .txt-file and wrtie the enciphered in an other .txt-file.

Ok, imagine the content of the cleartext.txt is "ABC" and I want the programme to convert A into X, B into Y and C into Z.
The output.txt should now contain the letters "XYZ" as a result of our working script.^^

I've looked at Aum83 (2D Games)which contains a lot of helpfull stuff to solve the problem, but I haven't figured it out anyway. =P

That's what I have...

Code:
STRING* data_str = "#10"; // the games can use up to 20 horizontal tiles
STRING* log_str = "#1"; 
STRING* temp_str = "#20"; // just a temporary string

function read_and_convert()
{
   var source_handle, output_handle, index, string_size;
   source_handle = file_open_read("cleartext.txt"); 
   output_handle = file_open_append("output.txt"); // open both files
   wait (3); // wait a bit
   while (file_str_read(source_handle, data_str) != -1) // run loop till the end
	{
		string_size = str_len(data_str);
		while (index < string_size) // go through all the characters, one by one
		{
			str_cpy (temp_str, data_str);
			str_clip(temp_str, index); 
			str_trunc(temp_str, string_size - index - 1); 
			if (str_cmp(temp_str, "A") == 1) // an A?
			{
				str_cpy(log_str, "X"); //convert it into X!
			}
			if (str_cmp(temp_str, "B") == 1)
			{
				str_cpy(log_str, "Y");
			}
			if (str_cmp(temp_str, "C") == 1)
			{
				str_cpy(log_str, "Z");
			}
			file_str_write(output_handle, log_str); 
			index += 1;
		}
		file_close(source_handle); // so let's close the file
	        file_close(output_handle);
	}
}



The output is " Z". Thanks for helping!

Last edited by Phonech; 10/10/09 18:38.