-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_test.py
45 lines (35 loc) · 1.03 KB
/
security_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import unittest
from security import (
xor_cipher_shuffle,
load_file,
shuffle_encrypt,
shuffle_decrypt,
xor_cipher,
)
class TestEncryption(unittest.TestCase):
def test_ecryption_decryption(self):
orig_file = "README.md"
enc_file = "README_enc.md"
xor_cipher_shuffle(
input_file=orig_file,
output_file=enc_file,
encrypt=True,
)
dec_file = "README_dec.md"
xor_cipher_shuffle(
input_file=enc_file,
output_file=dec_file,
encrypt=False,
)
orig_content = load_file(orig_file)
dec_content = load_file(dec_file)
self.assertEqual(orig_content, dec_content)
def test_string_encryption_decryption(self):
msg_orig = list(map(ord, "bisonai"))
msg = shuffle_encrypt(msg_orig)
msg = xor_cipher(msg)
msg = xor_cipher(msg)
msg_dec = shuffle_decrypt(msg)
self.assertEqual(msg_orig, msg_dec)
if __name__ == '__main__':
unittest.main()