Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[split #103] rewrite windows and android code #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions docs/topics/localfiles_encrypt_decrypt.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Simple XOR function differs can be written like this:
### **Python**

```py
def xor(string: str, key: int) -> str:
return ("").join(chr(ord(char) ^ key) for char in string)
def xor(data: bytes, key: int) -> bytes:
return bytes(byte ^ key for byte in data)
```

<!-- tabs:end -->
Expand All @@ -33,14 +33,18 @@ Programmatically decryption can be implemented like so:
### **Python**

```py
import base64
import gzip


def decrypt_data(data: str) -> str:
base64_decoded = base64.urlsafe_b64decode(xor(data, key=11).encode())
decompressed = gzip.decompress(base64_decoded)
return decompressed.decode()
from gzip import decompress
from base64 import urlsafe_b64decode


def decrypt_data(data: bytes) -> str:
size_mod_4 = len(data) % 4
if size_mod_4 > 0:
# size not divisible by 4
data = data[:-size_mod_4]
xored = bytes(byte ^ 11 for byte in data)
base64_decoded = urlsafe_b64decode(xored)
return decompress(base64_decoded).decode()
```

<!-- tabs:end -->
Expand Down Expand Up @@ -106,10 +110,14 @@ Encryption is done pretty much the same way but with opposite operations and ord
### **Python**

```py
def encrypt_data(data: str) -> str:
gzipped = gzip.compress(data.encode())
base64_encoded = base64.urlsafe_b64encode(gzipped)
return xor(base64_encoded.decode(), key=11)
from gzip import compress
from base64 import urlsafe_b64encode


def encrypt_data(xmlstring: str) -> bytes:
gzipped = compress(xmlstring.encode())
base64_encoded = urlsafe_b64encode(gzipped)
return bytes(byte ^ 11 for byte in base64_encoded)
```

<!-- tabs:end -->
Expand Down