Asian Text in a file

Blitz3D Forums/Blitz3D Programming/Asian Text in a file

dna(Posted 2017) [#1]
Hello

I was using some code to encrypt a text file. Using only XOR, the resulting text became all Asian text characters and the file took much more time to open.

I'm sure that many of you have come across this problem in the past.

What causes it?


xlsior(Posted 2017) [#2]
What causes it?


You told it to?

Most likely your resulting XOR text ended up resembling unicode encoding since you would have ended up using a lot of normally unprintable ASCII codes (>128). It happened to be displayed as some Asian lettering, but could have been anything. (Asian characters are stored in unicode, where instead of each byte representing a single character like in ASCII, it takes three or four bytes represent a character. If the first three/four XORed bytes of output file happened to be a valid match for some Asian unicode character, that's what it would show in a text editor)

If you want the resulting file to look 'normal', then don't save any ascii codes over 127, and especially don't use chr$(0) and chr$(255).


Dan(Posted 2017) [#3]
Please tell us, with which program have you opened the resulting text.

There is a difference between notepad, wordpad, Word and other text editing tools.
If the tool is able to open unicode, then the resulting text may be displayed as such.

Crimson Editor is able to switch the encoding type - between ascii, Unicode litle endian, Unicode big endian, UTF-8 with BOM or utf-8 without BOM.

If you are trying to open encrypted text, then the result is correct.


here is a simple xor test program, with this you can see how xor is working:



Actually, the next example shows how the encoding with xor really works:

(same as above example, but now the password (y) does not change)


see 3 functions Timer_Sec Timer_mSec and Screen for the missing userlib definitions (for the screen function)


dna(Posted 2017) [#4]
dAN

What id the api_GetSystemMetrics() function?

I get a compiler error


Bobysait(Posted 2017) [#5]
It's a function coming from windows dll (user32)

Just add it to your userlib links :

* get the decls file from the code archive and copy it to your userlib folder

or

* create a file in your blitz3d/userlibs folder (name it 'user32.decls')
* open it in your text editor
* add this to the file :
.lib "user32.dll"
api_GetSystemMetrics%(param%) : "GetSystemMetrics"


Then restart blitz3d. The new function should work.


Dan(Posted 2017) [#6]
or simply delete the function screen() and the first line ( screen(320,200) )
and uncomment the two graphic calls.

(btw: i wrote it in the code)

and at the end:

see 3 functions Timer_Sec Timer_mSec and Screen for the missing userlib definitions (for the screen function)

There i'v wrote you an answer on how to save the userlib definitions (arround 1 year ago) :p .

        DeskX=api_GetSystemMetrics(0)
	DeskY=api_GetSystemMetrics(1)


it gets the desktop screen resolution, which is not available in the pure blitz3d.


dna(Posted 2017) [#7]
@Dan

That is Clever that resolution. I never BB could do that

I also never knew you could display Hex with a Dollar sign in front of it. I always used 255