generated from Vl-Tershch/cs-102-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import unittest | ||
import os | ||
import sys | ||
parent_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")), "..")) | ||
sys.path.append(parent_dir) | ||
|
||
from src.lab2.caesar import encrypt_caesar, decrypt_caesar | ||
|
||
class TestCaesarCipher(unittest.TestCase): | ||
def test_encrypt_caesar(self): | ||
self.assertEqual(encrypt_caesar("ILOVEBEER"), 'LORYHEHHU') | ||
self.assertEqual(encrypt_caesar("bruuuuuuh"), 'euxxxxxxk') | ||
self.assertEqual(encrypt_caesar("9mm"), '9pp') | ||
self.assertEqual(encrypt_caesar(""), '') | ||
|
||
def test_decrypt_caesar(self): | ||
self.assertEqual(decrypt_caesar("LORYHEHHU"), 'ILOVEBEER') | ||
self.assertEqual(decrypt_caesar("euxxxxxxk"), 'bruuuuuuh') | ||
self.assertEqual(decrypt_caesar("9pp"), '9mm') | ||
self.assertEqual(decrypt_caesar(""), '') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
import os | ||
import sys | ||
parent_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")), "..")) | ||
sys.path.append(parent_dir) | ||
from src.lab2.rsa import is_prime, gcd, multiplicative_inverse, generate_keypair | ||
|
||
class TestRSAFunctions(unittest.TestCase): | ||
|
||
def test_is_prime(self): | ||
self.assertTrue(is_prime(2)) | ||
self.assertTrue(is_prime(11)) | ||
self.assertFalse(is_prime(8)) | ||
|
||
def test_gcd(self): | ||
self.assertEqual(gcd(12, 15), 3) | ||
self.assertEqual(gcd(3, 7), 1) | ||
|
||
def test_multiplicative_inverse(self): | ||
self.assertEqual(multiplicative_inverse(7, 40), 23) | ||
|
||
def test_generate_keypair(self): | ||
p, q = 11, 19 | ||
public_key, private_key = generate_keypair(p, q) | ||
|
||
# Проверка на то, что оба ключа имеют два элемента | ||
self.assertEqual(len(public_key), 2) | ||
self.assertEqual(len(private_key), 2) | ||
|
||
# Проверка, что оба ключа содержат только целые числа | ||
self.assertIsInstance(public_key[0], int) | ||
self.assertIsInstance(public_key[1], int) | ||
self.assertIsInstance(private_key[0], int) | ||
self.assertIsInstance(private_key[1], int) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
import os | ||
import sys | ||
parent_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")), "..")) | ||
sys.path.append(parent_dir) | ||
|
||
from src.lab2.vigenre import encrypt_vigenere, decrypt_vigenere | ||
|
||
class TestVigenereEncryptionDecryption(unittest.TestCase): | ||
def test_encrypt_vigenere(self): | ||
self.assertEqual(encrypt_vigenere("PYTHON", "A"), 'PYTHON') | ||
self.assertEqual(encrypt_vigenere("python", "a"), 'python') | ||
self.assertEqual(encrypt_vigenere("ATTACKATDAWN", "LEMON"), 'LXFOPVEFRNHR') | ||
|
||
def test_decrypt_vigenere(self): | ||
self.assertEqual(decrypt_vigenere("PYTHON", "A"), 'PYTHON') | ||
self.assertEqual(decrypt_vigenere("python", "a"), 'python') | ||
self.assertEqual(decrypt_vigenere("LXFOPVEFRNHR", "LEMON"), 'ATTACKATDAWN') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |