Is there a way to encrypt contents of a save file?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
boogerflicker
Newbie
Posts: 1
Joined: Fri Jul 25, 2014 8:58 pm

Is there a way to encrypt contents of a save file?

Post by boogerflicker »

I am working on a text adventure but I can't find a way to encrypt the save game. The way I am doing it now is with an XOR Encrypt/Decrypt function(not written by me) that encrypts each string before I write it to file. Then it loads the file and decrypts string by string. The only problem I am running in to is that this functioin only encrpyts strings. I have many integers like for health and gold that it won't encrypt. To get around this I turned each integer into a string before encrypting and writing to file. Then on Decrpyt I decrypt then convert back to integer with VAL. This gives me a problem that I can't find a way around. If the value was let's say 1000 I turn it into a string then encrypt. When I decrypt do VAL then print the result I end up with a 1 or a 0. Am I losing something somewhere in the STR$/VAL? Is there an easier way to do this? If there is let me know. If you think you can help me figure out why I'm losing the integer value and help me fix it then let me know and I'll put the code up.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: Is there a way to encrypt contents of a save file?

Post by burger2227 »

Post the code.

You can encrypt text by converting each text character into an ASCII code value and adding about 1 to 33 to it so that it becomes a different character. Don't exceed 255 for normal ASCII typing codes up to 122. Your encryption code must be loosing characters during the conversion or during decryption.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply