Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Created February 8, 2019 14:26
Show Gist options
  • Select an option

  • Save andrew-wilkes/ae55448bd23a6d3518fd776202ec8bac to your computer and use it in GitHub Desktop.

Select an option

Save andrew-wilkes/ae55448bd23a6d3518fd776202ec8bac to your computer and use it in GitHub Desktop.
Godot simple text file obfuscation
var d = File.new()
if d.file_exists(DIALOG_FILE):
encode_dialog()
d.open(ENC_DIALOG_FILE, File.READ)
dialog = flip_bytes(d.get_buffer(d.get_len())).get_string_from_utf8().split("###")
d.close()
func encode_dialog():
var file = File.new()
file.open(DIALOG_FILE, File.READ)
var text = file.get_as_text()
file.close()
file.open(ENC_DIALOG_FILE, File.WRITE)
var p = flip_bytes(text.to_utf8())
file.store_buffer(p)
file.close()
func flip_bytes(p):
for i in p.size():
p[i] *= -1
return p
@andrew-wilkes

Copy link
Copy Markdown
Author

The DIALOG_FILE is the text file and this is not included in the build for target platforms. The ENC_DIALOG_FILE is the name of the encrypted file that is included in builds such as file.zip

The encryption method may be any reversible algorithm inside of the flip_bytes function such as XORing bits.

@andrew-wilkes

Copy link
Copy Markdown
Author

Oh, and in my system, there is a delimiter of "###" between sections of text to allow them to be parsed into an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment