Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, alibaba), 1,426 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 4
Cryptography - How to encipher a .txt-file? #293329
10/10/09 18:37
10/10/09 18:37
Joined: Feb 2009
Posts: 38
Germany
P
Phonech Offline OP
Newbie
Phonech  Offline OP
Newbie
P

Joined: Feb 2009
Posts: 38
Germany
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.
Re: Cryptography - How to encipher a .txt-file? [Re: Phonech] #293337
10/10/09 19:16
10/10/09 19:16
Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
local vars are not guaranteed to be zero, init index like

index = 0;

also,

while (file_str_read(source_handle, data_str) != -1) this loop will work only one time, because after the first loop, you close the files.


3333333333
Re: Cryptography - How to encipher a .txt-file? [Re: Quad] #293341
10/10/09 19:34
10/10/09 19:34
Joined: Feb 2009
Posts: 38
Germany
P
Phonech Offline OP
Newbie
Phonech  Offline OP
Newbie
P

Joined: Feb 2009
Posts: 38
Germany
Got it! Thanks for your advice. smile

If someone is interested here is the fixed code:

Code:
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
   index = 0;
   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;
			wait(1);
		}
	   wait(1);
	}
	file_close(source_handle); // so let's close the file
	file_close(output_handle);
}



Re: Cryptography - How to encipher a .txt-file? [Re: Phonech] #293343
10/10/09 19:38
10/10/09 19:38
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Wouldn't it be easier to just operate on the ASCII value of the character. Eg, if you want A (65) to X (88), then you can just add 23. This would save a lot of checking what character is which.

Re: Cryptography - How to encipher a .txt-file? [Re: Phonech] #293378
10/11/09 05:57
10/11/09 05:57
Joined: Nov 2008
Posts: 26
France
H
Hirogens Offline
Newbie
Hirogens  Offline
Newbie
H

Joined: Nov 2008
Posts: 26
France

Why simple? when you can complicate.....


A7 Commercial License.
http://www.wormhole-the-game.com

AMD64 6000+, GTX 280 2GB, 4 GB Ram, Seven
Re: Cryptography - How to encipher a .txt-file? [Re: DJBMASTER] #293712
10/13/09 12:16
10/13/09 12:16
Joined: Feb 2009
Posts: 38
Germany
P
Phonech Offline OP
Newbie
Phonech  Offline OP
Newbie
P

Joined: Feb 2009
Posts: 38
Germany
How is that supposed to make it easier, especially if you want to be able to change the letters the cleartext converts in? Means A is not willing turn into an X everytime. tongue laugh

Re: Cryptography - How to encipher a .txt-file? [Re: Phonech] #293748
10/13/09 15:30
10/13/09 15:30
Joined: Feb 2005
Posts: 3,687
Hessen, Germany
T
Tempelbauer Offline
Expert
Tempelbauer  Offline
Expert
T

Joined: Feb 2005
Posts: 3,687
Hessen, Germany
for more security you can use AES from an external source
for example you could use a c-implementation of it: http://www.hoozi.com/Articles/AESEncryption.htm

Re: Cryptography - How to encipher a .txt-file? [Re: Tempelbauer] #293765
10/13/09 17:48
10/13/09 17:48
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
thx for the code..

Helps me alot to convert normal letters into special-symbols ^^


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Cryptography - How to encipher a .txt-file? [Re: Phonech] #293865
10/14/09 13:36
10/14/09 13:36
Joined: Aug 2009
Posts: 46
Deggendorf, Bayern
Fisch Offline
Newbie
Fisch  Offline
Newbie

Joined: Aug 2009
Posts: 46
Deggendorf, Bayern
I already made a similar program in C++.
I used the ASCII-Code, adding to every char 1.
This is called caesar-cryptography


The Internet is full of answers, even to never asked questions! laugh

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1