Hiding Strings

Blitz3D Forums/Blitz3D Beginners Area/Hiding Strings

Moore(Posted 2008) [#1]
Hey whats a good way of hiding stings in data packets and files?

Right now Im just shifting each value 1 bit left to save and one bit right to read. Its fairly fast and hard to read but easy to crack. any suggestions? Remember any solution has to be FAST. Thanks!


Here's the code I'm using:
Function write_string(file, txt$)
	x$ = string_shiftl(txt, 1)
	WriteString file, x
End Function

Function read_string(file)
	txt$ = ReadString(file) 
	Return string_shiftr(txt, 1)
End Function

Function string_shiftl$(txt$, start)
	l = Len(txt)
	If start > l Then 
		Return ""	
	Else
		Return Chr(Asc(Mid(txt, start, 1)) Shl 1) + string_shiftl(txt, start + 1)
	EndIf
End Function

Function string_shiftr$(txt$, start)
	l = Len(txt)
	If start > l Then 
		Return ""	
	Else
		Return Chr(Asc(Mid(txt, start, 1)) Shr 1) + string_shiftr(txt, start + 1)
	EndIf
End Function



Jasu(Posted 2008) [#2]
There are numerous ways you can crypt things. Using XOR is easiest.
http://www.blitzbasic.com/b3ddocs/command.php?name=Xor&ref=2d_cat
With it you can use the same function to crypt and decrypt. Instead of doing it in 4 byte level as in the example, you should change that to 1 byte level as strings are byte per character. The crypt mask should then be several bytes long (a string basically).

Always think that are you revealing your crypt mask if you crypt an empty string. If your strings are of variable length you could use different masks for different string sizes, or alter it using math on the string size.