Skip to content

Commit

Permalink
Merge branch 'main' into feature/LinkedList
Browse files Browse the repository at this point in the history
  • Loading branch information
Richajaishwal0 authored Nov 4, 2024
2 parents fb79fad + 32afd8b commit f933338
Show file tree
Hide file tree
Showing 25 changed files with 1,105 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: item.number,
labels: ['gssoc-ext', 'hacktoberfest-accepted']
labels: ['gssoc-ext']
});
const addLabel = async (label) => {
await github.rest.issues.addLabels({
Expand All @@ -36,4 +36,4 @@ jobs:
issue_number: item.number,
labels: [label]
});
};
};
1 change: 0 additions & 1 deletion DIRECTORY.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
/home/runner/work/_temp/6c91ad44-979f-45e2-97d0-57dc14af8567.sh: line 1: scripts/build_directory_md.py: No such file or directory
47 changes: 47 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Security Policy

## Reporting a Vulnerability

We take the security of our project seriously. If you discover a security vulnerability, please follow these steps:

1. **DO NOT** create a public GitHub issue for the vulnerability.
2. Send a report to our team through our Discord server: https://discord.
3. Provide as much information as possible about the vulnerability:
- Type of issue
- Full paths of source file(s) related to the issue
- Location of the affected source code
- Any special configuration required to reproduce the issue
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue

## Response Timeline

- We will acknowledge receipt of your vulnerability report within 48 hours.
- We will provide a more detailed response within 7 days.
- We will work on fixing the vulnerability and will keep you informed of our progress.
- Once the vulnerability is fixed, we will publicly disclose the security issue.

## Supported Versions

We will address security vulnerabilities in the following versions:

| Version | Supported |
| ------- | ------------------ |
| latest | :white_check_mark: |

## Best Practices

- Please give us reasonable time to address the issue before making any public disclosure.
- Act in good faith towards our users' privacy and data.
- Do not access or modify other users' data without explicit permission.

## Recognition

We appreciate the security research community's efforts in helping keep our project safe. Responsible disclosure of vulnerabilities helps us ensure the security and privacy of our users.

## Contact

For any security-related concerns, please contact us through:
- Discord: https://discord.
Thank you for helping keep our community safe!
31 changes: 31 additions & 0 deletions Tests/Cipher_algorithms/test_Rail_Fence_Cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
from pysnippets.Cipher_algorithms.Rail_Fence_Cipher import rail_fence_cipher_encrypt, rail_fence_cipher_decrypt

class TestRailFenceCipher(unittest.TestCase):

def test_encrypt(self):
self.assertEqual(rail_fence_cipher_encrypt("HELLO", 3), "HOELL")
self.assertEqual(rail_fence_cipher_encrypt("WEAREDISCOVEREDFLEEATONCE", 3), "WECRLTEERDSOEEFEAOCAIVDEN")

def test_decrypt(self):
self.assertEqual(rail_fence_cipher_decrypt("HOELL", 3), "HELLO")
self.assertEqual(rail_fence_cipher_decrypt("WECRLTEERDSOEEFEAOCAIVDEN", 3), "WEAREDISCOVEREDFLEEATONCE")

def test_invalid_input_encrypt(self):
with self.assertRaises(ValueError):
rail_fence_cipher_encrypt(12345, 3)
with self.assertRaises(ValueError):
rail_fence_cipher_encrypt("HELLO", "three")
with self.assertRaises(ValueError):
rail_fence_cipher_encrypt("HELLO", -1)

def test_invalid_input_decrypt(self):
with self.assertRaises(ValueError):
rail_fence_cipher_decrypt(12345, 3)
with self.assertRaises(ValueError):
rail_fence_cipher_decrypt("HOELL", "three")
with self.assertRaises(ValueError):
rail_fence_cipher_decrypt("HOELL", -1)

if __name__ == '__main__':
unittest.main()
38 changes: 38 additions & 0 deletions Tests/Cipher_algorithms/test_Vigenère_Cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unittest
from ...pysnippets.Cipher_algorithms.Vigenère_Cipher import VigenereCipher


class TestVigenereCipher(unittest.TestCase):
def setUp(self):
self.cipher = VigenereCipher("LEMON")

def test_encrypt(self):
plaintext = "ATTACK AT DAWN"
expected_ciphertext = "LXFOPV EF RNHR"
self.assertEqual(self.cipher.encrypt(plaintext), expected_ciphertext)

def test_decrypt(self):
ciphertext = "LXFOPV EF RNHR"
expected_plaintext = "ATTACKATDAWN"
self.assertEqual(self.cipher.decrypt(ciphertext), expected_plaintext)

def test_non_alpha_key(self):
with self.assertRaises(ValueError):
VigenereCipher("LEMON123")

def test_empty_string(self):
self.assertEqual(self.cipher.encrypt(""), "")
self.assertEqual(self.cipher.decrypt(""), "")

def test_case_insensitivity(self):
plaintext = "attack at dawn"
expected_ciphertext = "LXFOPV EF RNHR"
self.assertEqual(self.cipher.encrypt(plaintext), expected_ciphertext)

def test_special_characters_in_plaintext(self):
plaintext = "ATTACK! AT DAWN."
expected_ciphertext = "LXFOPV EF RNHR"
self.assertEqual(self.cipher.encrypt(plaintext), expected_ciphertext)

if __name__ == "__main__":
unittest.main()
17 changes: 17 additions & 0 deletions Tests/Cipher_algorithms/test_affine_cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest
from pysnippets.Cipher_algorithms.affine_cipher import AffineCipher

class TestAffineCipher(unittest.TestCase):
def setUp(self):
self.cipher = AffineCipher(a=5, b=8)

def test_encrypt(self):
self.assertEqual(self.cipher.encrypt('HELLO'), 'MJQQT')
self.assertEqual(self.cipher.encrypt('AFFINE CIPHER'), 'IHHWVC SWFRCP')

def test_decrypt(self):
self.assertEqual(self.cipher.decrypt('MJQQT'), 'HELLO')
self.assertEqual(self.cipher.decrypt('IHHWVC SWFRCP'), 'AFFINE CIPHER')

if __name__ == '__main__':
unittest.main()
74 changes: 74 additions & 0 deletions Tests/Cipher_algorithms/test_caesar_cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import unittest
import sys
import os

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')))
from pysnippets.Cipher_algorithms.caesar_cipher import CaesarCipher

class TestCaesarCipher(unittest.TestCase):
def setUp(self):
self.cipher = CaesarCipher()

def test_default_encryption(self):
message = "Hello, World!"
expected = "Khoor, Zruog!"
self.assertEqual(self.cipher.encrypt(message), expected)

def test_default_decryption(self):
encrypted = "Khoor, Zruog!"
expected = "Hello, World!"
self.assertEqual(self.cipher.decrypt(encrypted), expected)

def test_custom_shift(self):
custom_cipher = CaesarCipher(shift=5)
message = "Python Programming"
encrypted = custom_cipher.encrypt(message)
decrypted = custom_cipher.decrypt(encrypted)
self.assertEqual(decrypted, message)

def test_non_alphabetic_characters(self):
message = "Hello, World! 123"
encrypted = self.cipher.encrypt(message)
decrypted = self.cipher.decrypt(encrypted)
self.assertEqual(message, decrypted)

def test_brute_force_decryption(self):
message = "Hello, World!"
encrypted = self.cipher.encrypt(message)
decryptions = self.cipher.brute_force_decrypt(encrypted)
found_decryption = any(
decryption == message for _, decryption in decryptions
)
self.assertTrue(found_decryption)

def test_full_cycle(self):
message = "The quick brown fox jumps over the lazy dog!"
encrypted = self.cipher.encrypt(message)
decrypted = self.cipher.decrypt(encrypted)
self.assertEqual(message, decrypted)

def test_empty_string(self):
message = ""
encrypted = self.cipher.encrypt(message)
decrypted = self.cipher.decrypt(encrypted)
self.assertEqual(message, decrypted)

def test_large_shift(self):
custom_cipher = CaesarCipher(shift=30)
message = "Large Shift"
encrypted = custom_cipher.encrypt(message)
decrypted = custom_cipher.decrypt(encrypted)
self.assertEqual(decrypted, message)

def test_negative_shift(self):
custom_cipher = CaesarCipher(shift=-3)
message = "Negative Shift"
encrypted = custom_cipher.encrypt(message)
decrypted = custom_cipher.decrypt(encrypted)
self.assertEqual(decrypted, message)

def test_non_string_input(self):
with self.assertRaises(TypeError):
self.cipher.encrypt(12345)
with self.assertRaises(TypeError):
self.cipher.decrypt(12345)
32 changes: 32 additions & 0 deletions Tests/Cipher_algorithms/test_hill_cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest
from pysnippets.Cipher_algorithms.hill_cipher import HillCipher

class TestHillCipher(unittest.TestCase):
def setUp(self):
self.key_matrix = [[6, 24, 1], [13, 16, 10], [20, 17, 15]]
self.cipher = HillCipher(self.key_matrix)

def test_encrypt(self):
plaintext = "ACT"
expected_ciphertext = "POH"
self.assertEqual(self.cipher.encrypt(plaintext), expected_ciphertext)

def test_decrypt(self):
ciphertext = "POH"
expected_plaintext = "ACT"
self.assertEqual(self.cipher.decrypt(ciphertext), expected_plaintext)

def test_invalid_key_matrix(self):
with self.assertRaises(ValueError):
HillCipher([[1, 2], [3, 4]])

def test_invalid_plaintext_length(self):
with self.assertRaises(ValueError):
self.cipher.encrypt("ACTG")

def test_invalid_ciphertext_length(self):
with self.assertRaises(ValueError):
self.cipher.decrypt("POHG")

if __name__ == "__main__":
unittest.main()
17 changes: 17 additions & 0 deletions Tests/Cipher_algorithms/test_playfair_cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest
from pysnippets.Cipher_algorithms.playfair_cipher import playfair_encrypt, playfair_decrypt

class TestPlayfairCipher(unittest.TestCase):

def test_playfair_encrypt(self):
self.assertEqual(playfair_encrypt("HELLO", "KEYWORD"), "RIJVS")
self.assertEqual(playfair_encrypt("PLAYFAIR", "KEYWORD"), "RLBMZIXR")
self.assertEqual(playfair_encrypt("HACKTOBERFEST", "KEYWORD"), "RIBKZQKZBFXZ")

def test_playfair_decrypt(self):
self.assertEqual(playfair_decrypt("RIJVS", "KEYWORD"), "HELXLO")
self.assertEqual(playfair_decrypt("RLBMZIXR", "KEYWORD"), "PLAYFAIR")
self.assertEqual(playfair_decrypt("RIBKZQKZBFXZ", "KEYWORD"), "HACKTOBERFEST")

if __name__ == '__main__':
unittest.main()
50 changes: 50 additions & 0 deletions Tests/algorithms/test_bidirectional_bfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import unittest
from pysnippets.algorithms.bidirectional_bfs import bidirectional_search
class TestBidirectionalBFS(unittest.TestCase):

def setUp(self):
self.graph = {
'A': ['B', 'C'],
'B': ['A', 'D', 'E'],
'C': ['A', 'F'],
'D': ['B'],
'E': ['B', 'F'],
'F': ['C', 'E', 'G'],
'G': ['F']
}

def test_no_path(self):
disconnected_graph = {
'A': ['B'],
'B': ['A'],
'C': ['D'],
'D': ['C']
}
path = bidirectional_search(disconnected_graph, 'A', 'D')
self.assertIsNone(path)

def test_path(self):
path = bidirectional_search(self.graph, 'A', 'G')
self.assertEqual(path, ['A', 'C', 'F', 'G'])

def test_disconnected_graph(self):
two_node_graph = {'A': [], 'B': []}
path = bidirectional_search(two_node_graph, 'A', 'B')
self.assertIsNone(path)

def test_invalid_node(self):
with self.assertRaises(ValueError):
bidirectional_search(self.graph, 'A', 'Z')

def test_single_node_graph(self):
single_node_graph = {'A': []}
path = bidirectional_search(single_node_graph, 'A', 'A')
self.assertEqual(path, ['A'])

def test_graph_is_dictionary(self):
invalid_graph = ['hello']
with self.assertRaises(TypeError):
bidirectional_search(invalid_graph, 'hello', 'hello')



Loading

0 comments on commit f933338

Please sign in to comment.