Coverage for src/ensae_teaching_cs/data/crypt_helper.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-04-28 06:23 +0200

1""" 

2@file 

3@brief Data for competitions 

4""" 

5from pyquickhelper.filehelper.encryption import encrypt_stream, decrypt_stream 

6 

7 

8def encrypt_data(password, input, output): 

9 """ 

10 Encrypts a file. 

11 

12 @param input input filename 

13 @param output output filename 

14 @param password The encryption key - a string that must be either 16, 24 or 32 

15 bytes long. Longer keys are more secure. If the data to encrypt 

16 is in bytes, the key must be given in bytes too. 

17 """ 

18 if not isinstance(password, bytes): 

19 password = bytes(password, "ascii") 

20 encrypt_stream(password, input, output) 

21 

22 

23def decrypt_data(password, input, output): 

24 """ 

25 Decrypts a file. 

26 

27 @param input input filename 

28 @param output output filename 

29 @param password The encryption key - a string that must be either 16, 24 or 32 

30 bytes long. Longer keys are more secure. If the data to encrypt 

31 is in bytes, the key must be given in bytes too. 

32 """ 

33 if not isinstance(password, bytes): 

34 password = bytes(password, "ascii") 

35 decrypt_stream(password, input, output)