dp-prac 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dp_prac-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: dp-prac
3
+ Version: 0.1.0
4
+ Summary: Export seven beginner Data Privacy practicals as Python scripts
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Provides-Extra: run
8
+ Requires-Dist: cryptography>=40; extra == "run"
9
+
10
+ # DP Practicals
11
+
12
+ Install with `py -m pip install dp-prac` and run `dp-prac`.
13
+ On Windows you can also launch it with `py -m dp-prac`.
14
+
15
+ Choose a number from 1 to 7 to export the corresponding script, such as
16
+ `q1.py`, into the current folder. Existing files are preserved. Run an
17
+ exported script from that folder with a command such as `py q1.py`.
18
+
19
+ Q4 includes a demo `passwords.csv` and needs internet for the Pwned Passwords
20
+ check. Q5 includes `words.txt`. Q7 needs `cryptography`, which you can install
21
+ with `py -m pip install "dp-prac[run]"`. The menu itself has no runtime
22
+ dependencies.
@@ -0,0 +1,13 @@
1
+ # DP Practicals
2
+
3
+ Install with `py -m pip install dp-prac` and run `dp-prac`.
4
+ On Windows you can also launch it with `py -m dp-prac`.
5
+
6
+ Choose a number from 1 to 7 to export the corresponding script, such as
7
+ `q1.py`, into the current folder. Existing files are preserved. Run an
8
+ exported script from that folder with a command such as `py q1.py`.
9
+
10
+ Q4 includes a demo `passwords.csv` and needs internet for the Pwned Passwords
11
+ check. Q5 includes `words.txt`. Q7 needs `cryptography`, which you can install
12
+ with `py -m pip install "dp-prac[run]"`. The menu itself has no runtime
13
+ dependencies.
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dp-prac"
7
+ version = "0.1.0"
8
+ description = "Export seven beginner Data Privacy practicals as Python scripts"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+
12
+ [project.optional-dependencies]
13
+ run = ["cryptography>=40"]
14
+
15
+ [project.scripts]
16
+ dp-prac = "dp_prac.__main__:main"
17
+
18
+ [tool.setuptools.packages.find]
19
+ where = ["src"]
20
+ namespaces = false
21
+
22
+ [tool.setuptools.package-data]
23
+ dp_prac = ["solutions/*.txt", "solutions/*.csv"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,5 @@
1
+ from dp_prac.__main__ import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ main()
File without changes
@@ -0,0 +1,61 @@
1
+ from importlib.resources import files
2
+ from pathlib import Path
3
+ import sys
4
+
5
+
6
+ PRACTICALS = (
7
+ "Caesar cipher",
8
+ "Rail Fence cipher",
9
+ "SHA-256 password hash",
10
+ "Check for leaked passwords",
11
+ "Generate a passphrase",
12
+ "Exhaustive search puzzle",
13
+ "Sign and verify a document",
14
+ )
15
+
16
+ SAMPLE_FILES = {"4": "passwords.csv", "5": "words.txt"}
17
+
18
+
19
+ def export_file(source, destination):
20
+ try:
21
+ content = source.read_bytes()
22
+ with destination.open("xb") as output:
23
+ output.write(content)
24
+ except FileExistsError:
25
+ print(f"{destination.name} already exists.")
26
+ except OSError as error:
27
+ print(f"Could not create {destination.name}: {error}", file=sys.stderr)
28
+ else:
29
+ print(f"Created {destination}")
30
+
31
+
32
+ def main():
33
+ directory = Path.cwd()
34
+ solutions = files("dp_prac").joinpath("solutions")
35
+ choices = {str(number): title for number, title in enumerate(PRACTICALS, 1)}
36
+ print("DP Practicals")
37
+ print(f"Output folder: {directory}\n")
38
+ for number, title in choices.items():
39
+ print(f"{number}. {title}")
40
+ print("0. Exit")
41
+
42
+ while True:
43
+ try:
44
+ choice = input("\nChoose a question (1-7), or 0 to exit: ").strip()
45
+ except (EOFError, KeyboardInterrupt):
46
+ print()
47
+ return
48
+ if choice == "0":
49
+ return
50
+ if choice not in choices:
51
+ print("Enter a number from 1 to 7, or 0 to exit.")
52
+ continue
53
+
54
+ export_file(solutions.joinpath(f"q{choice}.txt"), directory / f"q{choice}.py")
55
+ if choice in SAMPLE_FILES:
56
+ sample = SAMPLE_FILES[choice]
57
+ export_file(solutions.joinpath(sample), directory / sample)
58
+
59
+
60
+ if __name__ == "__main__":
61
+ main()
@@ -0,0 +1 @@
1
+ student1,password
@@ -0,0 +1,20 @@
1
+ def shift_letters(text, shift):
2
+ result = ""
3
+ for letter in text:
4
+ if "A" <= letter <= "Z":
5
+ alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6
+ elif "a" <= letter <= "z":
7
+ alphabet = "abcdefghijklmnopqrstuvwxyz"
8
+ else:
9
+ result += letter
10
+ continue
11
+ result += alphabet[(alphabet.index(letter) + shift) % 26]
12
+ return result
13
+
14
+
15
+
16
+ text = input("Enter text (example: Hello!): ")
17
+ shift = int(input("Enter a shift (example: 3): "))
18
+ encrypted = shift_letters(text, shift)
19
+ print("Encrypted:", encrypted)
20
+ print("Decrypted:", shift_letters(encrypted, -shift))
@@ -0,0 +1,31 @@
1
+ text = input("Enter text (example: HELLOWORLD): ")
2
+ rails = int(input("Enter the number of rails (example: 3): "))
3
+ path = []
4
+ rail = 0
5
+ step = 1
6
+ for letter in text:
7
+ path.append(rail)
8
+ if rail == 0:
9
+ step = 1
10
+ elif rail == rails - 1:
11
+ step = -1
12
+ rail += step
13
+
14
+
15
+ positions = []
16
+ for rail in range(rails):
17
+ for index in range(len(text)):
18
+ if path[index] == rail:
19
+ positions.append(index)
20
+
21
+
22
+ encrypted = ""
23
+ for index in positions:
24
+ encrypted += text[index]
25
+ print("Encrypted:", encrypted)
26
+
27
+
28
+ decrypted = [""] * len(text)
29
+ for index, letter in zip(positions, encrypted):
30
+ decrypted[index] = letter
31
+ print("Decrypted:", "".join(decrypted))
@@ -0,0 +1,10 @@
1
+ from hashlib import sha256
2
+
3
+
4
+
5
+ def hash_password(password):
6
+ return sha256(password.encode()).hexdigest()
7
+
8
+
9
+
10
+ print("SHA-256:", hash_password(input("Demo password (example: abc): ")))
@@ -0,0 +1,21 @@
1
+ from csv import reader
2
+ from hashlib import sha1
3
+ from urllib.request import Request, urlopen
4
+
5
+
6
+ with open("passwords.csv", encoding="utf-8", newline="") as file:
7
+ for username, password in reader(file):
8
+ digest = sha1(password.encode()).hexdigest().upper()
9
+ request = Request(
10
+ "https://api.pwnedpasswords.com/range/" + digest[:5],
11
+ headers={"Add-Padding": "true"},
12
+ )
13
+ with urlopen(request, timeout=10) as response:
14
+ lines = response.read().decode().splitlines()
15
+ status = "No match found"
16
+ for line in lines:
17
+ suffix, count = line.split(":")
18
+ if suffix == digest[5:] and int(count) > 0:
19
+ status = "Leaked"
20
+ break
21
+ print(username + ":", status)
@@ -0,0 +1,9 @@
1
+ from pathlib import Path
2
+ from secrets import choice
3
+
4
+
5
+ words = Path("words.txt").read_text(encoding="utf-8").split()
6
+ picked = []
7
+ for _ in range(4):
8
+ picked.append(choice(words))
9
+ print("Passphrase:", "-".join(picked))
@@ -0,0 +1,9 @@
1
+ from itertools import product
2
+
3
+
4
+ for first, second in product("ABC", repeat=2):
5
+ pair = first + second
6
+ print(pair)
7
+ if pair == "BC":
8
+ print("Puzzle solved")
9
+ break
@@ -0,0 +1,20 @@
1
+ from pathlib import Path
2
+ from cryptography.hazmat.primitives.asymmetric.ed25519 import (
3
+ Ed25519PrivateKey, Ed25519PublicKey,
4
+ )
5
+
6
+
7
+ # Sender
8
+ document = Path("notice.txt")
9
+ document.write_text("Practical starts at 10 AM.", encoding="utf-8")
10
+ private_key = Ed25519PrivateKey.generate()
11
+ Path("notice.sig").write_bytes(private_key.sign(document.read_bytes()))
12
+ Path("public.key").write_bytes(private_key.public_key().public_bytes_raw())
13
+
14
+
15
+ # Receiver
16
+ public_key = Ed25519PublicKey.from_public_bytes(
17
+ Path("public.key").read_bytes()
18
+ )
19
+ public_key.verify(Path("notice.sig").read_bytes(), document.read_bytes())
20
+ print("Signature verified.")
@@ -0,0 +1,4 @@
1
+ river
2
+ mango
3
+ cloud
4
+ stone
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: dp-prac
3
+ Version: 0.1.0
4
+ Summary: Export seven beginner Data Privacy practicals as Python scripts
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Provides-Extra: run
8
+ Requires-Dist: cryptography>=40; extra == "run"
9
+
10
+ # DP Practicals
11
+
12
+ Install with `py -m pip install dp-prac` and run `dp-prac`.
13
+ On Windows you can also launch it with `py -m dp-prac`.
14
+
15
+ Choose a number from 1 to 7 to export the corresponding script, such as
16
+ `q1.py`, into the current folder. Existing files are preserved. Run an
17
+ exported script from that folder with a command such as `py q1.py`.
18
+
19
+ Q4 includes a demo `passwords.csv` and needs internet for the Pwned Passwords
20
+ check. Q5 includes `words.txt`. Q7 needs `cryptography`, which you can install
21
+ with `py -m pip install "dp-prac[run]"`. The menu itself has no runtime
22
+ dependencies.
@@ -0,0 +1,21 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/dp-prac/__init__.py
4
+ src/dp-prac/__main__.py
5
+ src/dp_prac/__init__.py
6
+ src/dp_prac/__main__.py
7
+ src/dp_prac.egg-info/PKG-INFO
8
+ src/dp_prac.egg-info/SOURCES.txt
9
+ src/dp_prac.egg-info/dependency_links.txt
10
+ src/dp_prac.egg-info/entry_points.txt
11
+ src/dp_prac.egg-info/requires.txt
12
+ src/dp_prac.egg-info/top_level.txt
13
+ src/dp_prac/solutions/passwords.csv
14
+ src/dp_prac/solutions/q1.txt
15
+ src/dp_prac/solutions/q2.txt
16
+ src/dp_prac/solutions/q3.txt
17
+ src/dp_prac/solutions/q4.txt
18
+ src/dp_prac/solutions/q5.txt
19
+ src/dp_prac/solutions/q6.txt
20
+ src/dp_prac/solutions/q7.txt
21
+ src/dp_prac/solutions/words.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ dp-prac = dp_prac.__main__:main
@@ -0,0 +1,3 @@
1
+
2
+ [run]
3
+ cryptography>=40
@@ -0,0 +1,2 @@
1
+ dp-prac
2
+ dp_prac