Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a2c455b

Browse files
Adding new knowledge about XOR Cipher
1 parent 94b6004 commit a2c455b

File tree

1 file changed

+85
-14
lines changed

1 file changed

+85
-14
lines changed

β€ŽREADME.md

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -688,38 +688,109 @@ with open(relative_to_assets('Data/security/API'), 'wb') as f:
688688

689689
```
690690

691+
<h3>XOR Cipher</h3>
692+
<p>E</p>
691693

692-
For reading Key from file:
694+
Encrypting:
693695

694696
```python
697+
#! /usr/bin/env python3
695698
import base64
699+
import os
696700
import pathlib
701+
import re
702+
from pathlib import Path
703+
704+
# Dynamic File Path Solution
705+
KEY_PATH = pathlib.Path(__file__).parent.absolute()
706+
707+
708+
def relative_to_assets(path: str) -> Path:
709+
return KEY_PATH / Path(path)
710+
711+
712+
def encryptSecurity():
713+
# Use external script to make base64 or https://www.base64encode.org/
714+
key = "MTMy" # up 255
715+
key = base64.b64decode(key)
716+
cleanKey = re.sub(
717+
r"[^A-Za-z0-9-]", "", key.decode("utf-8"))
718+
finalKey = int(cleanKey)
719+
720+
loadEnc00 = open(relative_to_assets("Data/security/.KEY"), "rb")
721+
byteReaderData = loadEnc00.read()
722+
loadEnc00.close()
723+
724+
byteReaderData = bytearray(byteReaderData)
725+
for index, value in enumerate(byteReaderData):
726+
byteReaderData[index] = value ^ finalKey
727+
728+
Enc = open(relative_to_assets("Data/security/.KEY.nclmE"), "wb")
729+
Enc.write(byteReaderData)
730+
Enc.close()
731+
732+
# Delete Data/security/KEY
733+
os.remove(relative_to_assets("Data/security/.KEY"))
734+
735+
736+
encryptSecurity()
737+
738+
```
739+
740+
Decrypting:
741+
742+
```python
743+
#! /usr/bin/env python3
744+
import base64
697745
import os
746+
import pathlib
698747
import re
748+
import string
699749
from pathlib import Path
750+
import signal
700751

701752
# Dynamic File Path Solution
702-
API_PATH = pathlib.Path(__file__).parent.absolute()
753+
KEY_PATH = pathlib.Path(__file__).parent.absolute()
703754

704755

705756
def relative_to_assets(path: str) -> Path:
706-
return API_PATH / Path(path)
757+
return KEY_PATH / Path(path)
758+
759+
760+
def signal_handler(sig, frame):
761+
# If the program exits then remove important files.
762+
os.remove(relative_to_assets("Data/security/.tmp/.KEY"))
763+
exit()
764+
707765

708-
API_CONTENT = None
709-
# πŸ” Security execution => READING API FROM FILE
766+
def decryptSecurity():
767+
# Use external script to make base64 or https://www.base64encode.org/
768+
key = "MTMy" # up 255
769+
key = base64.b64decode(key)
770+
cleanKey = re.sub(
771+
r"[^A-Za-z0-9-]", "", key.decode("utf-8"))
772+
finalKey = int(cleanKey)
710773

774+
loadEnc00 = open(relative_to_assets(
775+
"Data/security/.KEY.nclmE"), "rb").read()
711776

712-
def API_SEC():
713-
global API_CONTENT
714-
# Security measures
715-
API_CONTENT = open(relative_to_assets("Data/security/API"), "r").read()
716-
API_DECODED = base64.b64decode(API_CONTENT.encode("utf-8"))
777+
byteReader = bytearray(loadEnc00)
778+
for index, value in enumerate(byteReader):
779+
byteReader[index] = value ^ finalKey
717780

718-
# Regular expression to remove garbage characters, do not remove "-"
719-
API_DECODED_CLEAN = re.sub(
720-
r"[^A-Za-z0-9-]", "", API_DECODED.decode("utf-8"))
781+
decEnc = open(relative_to_assets("Data/security/.tmp/.KEY"), "wb")
782+
decEnc.write(byteReader)
783+
784+
785+
try:
786+
# signal handler for "CTRL + C"
787+
signal.signal(signal.SIGINT, signal_handler)
788+
decryptSecurity()
789+
signal.pause()
790+
except:
791+
# In exeption remove important files.
792+
os.remove(relative_to_assets("Data/security/.tmp/.KEY"))
721793

722-
return API_DECODED_CLEAN
723794
```
724795

725796
## πŸ“„ License

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /