11import sys , getopt
2- from Crypto .Cipher import AES
32import os
43from os import urandom
54import hashlib
87import subprocess
98from pathlib import Path
109
11-
1210characters = string .ascii_letters + string .digits
1311password = '' .join (random .choice (characters ) for i in range (16 ))
1412
15-
1613KEY_XOR = password .replace ('"' ,'-' ).replace ('\' ' ,'-' )
17- KEY_AES = urandom (16 )
18-
19-
20- def pad (s ):
21- return s + (AES .block_size - len (s ) % AES .block_size ) * chr (AES .block_size - len (s ) % AES .block_size ).encode ('ISO-8859-1' )
22-
23-
24- def aesenc (plaintext , key ):
25- k = hashlib .sha256 (key ).digest ()
26- iv = 16 * b'\x00 '
27- plaintext = pad (plaintext )
28- cipher = AES .new (k , AES .MODE_CBC , iv )
29- output = cipher .encrypt (plaintext )
30- return output
31-
3214
3315def xor (data , key ):
34-
3516 key = str (key )
3617 l = len (key )
3718 output_str = ""
@@ -40,7 +21,7 @@ def xor(data, key):
4021 current = data [i ]
4122 current_key = key [i % len (key )]
4223 output_str += chr (ord (current ) ^ ord (current_key ))
43-
24+
4425 return output_str
4526
4627
@@ -49,7 +30,6 @@ def printCiphertext(ciphertext):
4930
5031
5132def generateConfig (outputFilePath ):
52-
5333 fileConfigJsonPath = os .path .join (Path (__file__ ).parent , 'BeaconConfig.json' )
5434 fileConfig = open (fileConfigJsonPath , 'r' )
5535 config = fileConfig .read ()
@@ -69,18 +49,13 @@ def generateConfig(outputFilePath):
6949 test = printCiphertext (KEY_XOR )
7050 fileClearContent = fileClearContent .replace ("KEY_XOR" , test )
7151
72-
7352 fileEncrypt .write (fileClearContent )
74-
7553 fileEncrypt .close ()
76-
7754 return
7855
7956
8057def main (argv ):
81-
8258 outputFilePath = "./cryptDef.hpp"
83-
8459 opts , args = getopt .getopt (argv ,"hb:o:" ,["output=" ])
8560 for opt , arg in opts :
8661 if opt == '-h' :
@@ -90,11 +65,8 @@ def main(argv):
9065 outputFilePath = arg
9166
9267 print ('[+] Generate config:' )
93-
9468 generateConfig (outputFilePath )
9569
9670
97-
9871if __name__ == "__main__" :
9972 main (sys .argv [1 :])
100-
0 commit comments