@@ -278,7 +278,7 @@ def decrypt(encrypted_code:str, mapping: dict =_character_map) -> str:
278278
279279 return original_code
280280
281- def run (encrypted_file : str , mapping : dict = _character_map ) -> None :
281+ def run (encrypted_file : str , mapping : dict = _character_map ) -> bool :
282282 """
283283 Decrypt and execute the Python code embedded in the specified file.
284284
@@ -289,23 +289,28 @@ def run(encrypted_file: str, mapping: dict = _character_map) -> None:
289289 Returns:
290290 None
291291 """
292- # Read the encrypted code from the file
293- with open (encrypted_file , 'r' ) as file :
294- content = file .read ()
295-
296- # Extract the encrypted code from the comments
297- encrypted_code = re .search (r'# (.+)' , content ).group (1 )
298- encrypted_code = encrypted_code .replace ("# " , '' )
299-
300- # Decrypt the code
301- decrypted_code = decrypt_code (encrypted_code , mapping )
302-
303- # Execute the decrypted Python code
304- exec (decrypted_code )
305-
306- print ("Code decrypted and executed successfully." )
307-
308- def decrypt_to_file (encrypted_file : str , output_file : str , mapping : dict = _character_map ) -> None :
292+ try :
293+ # Read the encrypted code from the file
294+ with open (encrypted_file , 'r' ) as file :
295+ content = file .read ()
296+
297+ # Extract the encrypted code from the comments
298+ encrypted_code = re .search (r'# (.+)' , content ).group (1 )
299+ encrypted_code = encrypted_code .replace ("# " , '' )
300+
301+ # Decrypt the code
302+ decrypted_code = decrypt_code (encrypted_code , mapping )
303+
304+ # Execute the decrypted Python code
305+ exec (decrypted_code )
306+
307+ # I modify the print statement global so this will break for me.
308+ #print("Code decrypted and executed successfully.")
309+ return true
310+ except Exception :
311+ return false
312+
313+ def decrypt_to_file (encrypted_file : str , output_file : str , mapping : dict = _character_map ) -> bool :
309314 """
310315 Decrypt the code embedded in the specified file and write it to an output file.
311316
@@ -317,19 +322,25 @@ def decrypt_to_file(encrypted_file: str, output_file: str, mapping: dict = _char
317322 Returns:
318323 None
319324 """
320- # Read the encrypted code from the file
321- with open (encrypted_file , 'r' ) as file :
322- content = file .read ()
323-
324- # Extract the encrypted code from the comments
325- encrypted_code = re .search (r'# (.+)' , content ).group (1 )
326- encrypted_code = encrypted_code .replace ("# " , '' )
327-
328- # Decrypt the code
329- decrypted_code = decrypt_code (encrypted_code , mapping )
330-
331- # Write the decrypted code to the specified output file
332- with open (output_file , 'w' ) as file :
333- file .write (decrypted_code )
334-
335- print (f"Decrypted code written to { output_file } ." )
325+ try :
326+
327+ # Read the encrypted code from the file
328+ with open (encrypted_file , 'r' ) as file :
329+ content = file .read ()
330+
331+ # Extract the encrypted code from the comments
332+ encrypted_code = re .search (r'# (.+)' , content ).group (1 )
333+ encrypted_code = encrypted_code .replace ("# " , '' )
334+
335+ # Decrypt the code
336+ decrypted_code = decrypt_code (encrypted_code , mapping )
337+
338+ # Write the decrypted code to the specified output file
339+ with open (output_file , 'w' ) as file :
340+ file .write (decrypted_code )
341+
342+ # I modify the print global so this will break for me.
343+ #print(f"Decrypted code written to {output_file}.")
344+ return true
345+ except Exception :
346+ return false
0 commit comments