
-----------------------------------
Tony
Fri Dec 27, 2002 11:39 pm


-----------------------------------
by using chr() and ord() functions

basically
chr(ord("a")) will output "a"... now if you change it to chr(ord("a")+1) it will output "b" because of that +1

if you change that +1 to something more complex... like a math expression or something, you can get a less guessable encription. Make sure that ord(character) + expression is no greater then 255 and not less then about 15-20 or so (some characters are not printable).

You can obtain an ASCII value of any character by using
ord(character)
and convert it back to character using
chr(ASCII value)

Edit: wow, server's timing is off... or something... anyway, this suppost to be a reply

-----------------------------------
azndragon
Fri Dec 27, 2002 11:43 pm

Encoding Save File
-----------------------------------

var text:string
var codeword : string

put "enter a word"
get text

for i:1..length(text) 
put chr(ord(text(i))+5).. 
end for

[Insert something that sets the converted value to variable codeword]

put "Coded word: ",codeword,""

Let's say I want to encrpyt a string with the above code. How would I use this code so that the converted text is set as another variable? 

Ex. "Enter a word" hi
      Coded word: mn

-----------------------------------
azndragon
Fri Dec 27, 2002 11:44 pm


-----------------------------------
I know how to do it, but I'm just missing the part where the encoded value is set as another variable. Once that's set, I can get my entire encryption to work.

-----------------------------------
Tony
Fri Dec 27, 2002 11:48 pm


-----------------------------------
in that case it should be something like this:

code:
var text : string := "tony"
var textnew : string := ""

for i:1.. length(text)
textnew := textnew + chr(ord(text(i))+1)
end for

put textnew
--------

textnew now holds "upoz" which will result back to "tony" if +1 is replaced with an opposite action (-1)

-----------------------------------
Izzy
Fri Dec 27, 2002 11:49 pm


-----------------------------------
Take a look at this :D
code:
var text:string 
var codeword : string := ""
var newletter : string

put "enter a word" 
get text 

for i:1..length(text) 
newletter := chr(ord(text(i))+5)
codeword := codeword + newletter
end for 

put "Coded word: ",codeword,""
-------
- Izzy

Edited by Tony: hmm... '['code']' doesn't seem to work anymore...  :? So I replaced it to make text visible

Edited by Tony again : nevermind... I think its just for me... :evil:

-----------------------------------
azndragon
Sat Dec 28, 2002 12:16 am


-----------------------------------
Thanks for the help guys. Okay, let me make sure I have this right before I start, because it's a pretty time consuming process to encrypt and decrypt 100+ variables :D . First, I will start off with the declaring variables statement.

var character_name : string := ""
var character_name_code : string := ""
var character_agility : int
var character_agility_code : string


Encrypting Text

for i : 1 .. length (character_name)
        character_name_code := character_name_code + chr (ord (character_name (i)) + 8)
    end for


Encrypting Numbers

character_agility_code := chr (character_agility - 3)


Decrypting Text

for i : 1 .. length (character_name_code)
        character_name:= character_name + chr (ord (character_name_code (i)) - 8)
    end for


Decrypting Numbers

character_agility:= ord (character_agility_code)
character_agility := character_agility + 3


-----------------------------------
Tony
Sat Dec 28, 2002 12:22 am


-----------------------------------
ya, you got that right...

though if you have 100+ variables, I sujest making a function instead of rewriting the code 100+ times  :wink:

-----------------------------------
azndragon
Sat Dec 28, 2002 10:02 am


-----------------------------------
How would I use a function to encrypt multiple variables?

-----------------------------------
Tony
Sat Dec 28, 2002 1:39 pm


-----------------------------------
you write a function to encript string

something like


function encript(text:string):string
var textNew:string :=""
for i : 1 .. length (text) 
        textNew:= textNew+ chr (ord (text(i)) + 8) 
end for 
result textNew
end encript



now just call this function every time you need to encript something, such as

put encript("tony")
or
var_text_encripted := encript(var_text)

-----------------------------------
azndragon
Sat Dec 28, 2002 1:42 pm


-----------------------------------
var character_skill2_uses : int := 0
var character_skill2_uses_code : string

I'm getting a error:

"Value passed to 'chr' is  255." under the line of:

character_skill2_uses_code := chr (character_skill2_uses + 70)

It works when I run it by itself in a separate file, but when I try to add it to my RPG, it gives that error.

-----------------------------------
Tony
Sat Dec 28, 2002 10:00 pm


-----------------------------------
thats because there're only 255 ASCII characters... so if your skill_level + 70 adds up to more then 255, there's no character with that value and nothing can be outputed.

thats why I worrned you to make sure that after math you result is >0 and 