@@ -688,38 +688,109 @@ with open(relative_to_assets('Data/security/API'), 'wb') as f:
688
688
689
689
```
690
690
691
+ <h3 >XOR Cipher</h3 >
692
+ <p >E</p >
691
693
692
- For reading Key from file :
694
+ Encrypting :
693
695
694
696
``` python
697
+ # ! /usr/bin/env python3
695
698
import base64
699
+ import os
696
700
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
697
745
import os
746
+ import pathlib
698
747
import re
748
+ import string
699
749
from pathlib import Path
750
+ import signal
700
751
701
752
# Dynamic File Path Solution
702
- API_PATH = pathlib.Path(__file__ ).parent.absolute()
753
+ KEY_PATH = pathlib.Path(__file__ ).parent.absolute()
703
754
704
755
705
756
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
+
707
765
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)
710
773
774
+ loadEnc00 = open (relative_to_assets(
775
+ " Data/security/.KEY.nclmE" ), " rb" ).read()
711
776
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
717
780
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" ))
721
793
722
- return API_DECODED_CLEAN
723
794
```
724
795
725
796
## π License
0 commit comments