cn-command-kit 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: cn-command-kit
3
+ Version: 0.1.0
4
+ Summary: Computer Networks lab programs command line library
5
+ Author: GHOST
6
+ Requires-Python: >=3.8
@@ -0,0 +1,15 @@
1
+ cnkit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ cnkit/cli.py,sha256=H4KJQ1-Tir7NmYCSKGnZSSNmg4g54Da4CbUMIGIWSjM,597
3
+ cnkit/texts/p1.txt,sha256=hdltiYEpO2qF1Z-1P8ivOO9KX0b2ciYK1gP4Mq6UtLo,1300
4
+ cnkit/texts/p2.txt,sha256=ihOfQh_4PN66bShUcbzwRAAQt7dCrGVlUF_c6Wx4k_o,911
5
+ cnkit/texts/p3.txt,sha256=QQMYGpuIl0Ko0SkRjOuR5ZEK9ujpPaMH9Jo6MgYQDUA,1684
6
+ cnkit/texts/p4.txt,sha256=SOwp59ree8CPEu93y8hJm7cSIWD3Lw6ModWjxKNp8ok,2645
7
+ cnkit/texts/p5.txt,sha256=mxvAoSm7rXolZnZ4BagDZRgSVUVDNeHI59ESHr_4atI,1192
8
+ cnkit/texts/p6.txt,sha256=1qAJ4-kXC__z3L6xGianFOUR1ydjEjWRSzbRrNRFC-E,827
9
+ cnkit/texts/p7.txt,sha256=8lBOB4-7dQVXJqyJ2F1i4b7bAZeyoFK31pvYu93zv5E,1350
10
+ cnkit/texts/p8.txt,sha256=i2xajH0RJDUUlTTBR3ytQw5edb7qctjRUWh9mG3C1Zk,1386
11
+ cn_command_kit-0.1.0.dist-info/METADATA,sha256=QpYcCadyifzyk5sYaHI1x7cnHjKq0tZTH-CAnO4UR9o,162
12
+ cn_command_kit-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
13
+ cn_command_kit-0.1.0.dist-info/entry_points.txt,sha256=lncUS2rNWadMmhDcQ-oyrHR6qkRDw2CKy03-JUOEXdE,200
14
+ cn_command_kit-0.1.0.dist-info/top_level.txt,sha256=Ab6DXrmjjUHi9HjOUAK-2UoSt6-MWO0XB5pWY7Sii8s,6
15
+ cn_command_kit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,11 @@
1
+ [console_scripts]
2
+ p1 = cnkit.cli:p1
3
+ p10 = cnkit.cli:p10
4
+ p2 = cnkit.cli:p2
5
+ p3 = cnkit.cli:p3
6
+ p4 = cnkit.cli:p4
7
+ p5 = cnkit.cli:p5
8
+ p6 = cnkit.cli:p6
9
+ p7 = cnkit.cli:p7
10
+ p8 = cnkit.cli:p8
11
+ p9 = cnkit.cli:p9
@@ -0,0 +1 @@
1
+ cnkit
cnkit/__init__.py ADDED
File without changes
cnkit/cli.py ADDED
@@ -0,0 +1,40 @@
1
+ from pathlib import Path
2
+
3
+ def show_program(number):
4
+ file_path = Path(__file__).parent / "texts" / f"p{number}.txt"
5
+
6
+ if file_path.exists():
7
+ print(file_path.read_text(encoding="utf-8"))
8
+ else:
9
+ print("Program not found!")
10
+
11
+
12
+ def p1():
13
+ show_program(1)
14
+
15
+ def p2():
16
+ show_program(2)
17
+
18
+ def p3():
19
+ show_program(3)
20
+
21
+ def p4():
22
+ show_program(4)
23
+
24
+ def p5():
25
+ show_program(5)
26
+
27
+ def p6():
28
+ show_program(6)
29
+
30
+ def p7():
31
+ show_program(7)
32
+
33
+ def p8():
34
+ show_program(8)
35
+
36
+ def p9():
37
+ show_program(9)
38
+
39
+ def p10():
40
+ show_program(10)
cnkit/texts/p1.txt ADDED
@@ -0,0 +1,44 @@
1
+ import java.util.*;
2
+
3
+ class CRC {
4
+ static String divide(String data, String key) {
5
+ char[] a = data.toCharArray();
6
+
7
+ for (int i = 0; i <= a.length - key.length(); i++) {
8
+ if (a[i] == '1') {
9
+ for (int j = 0; j < key.length(); j++) {
10
+ a[i + j] = (a[i + j] == key.charAt(j)) ? '0' : '1';
11
+ }
12
+ }
13
+ }
14
+ return new String(a).substring(a.length - key.length() + 1);
15
+ }
16
+
17
+ public static void main(String[] args) {
18
+ Scanner sc = new Scanner(System.in);
19
+
20
+ System.out.print("Enter data: ");
21
+ String data = sc.next();
22
+
23
+ System.out.print("Enter generator: ");
24
+ String key = sc.next();
25
+
26
+ String code = data + "0".repeat(key.length() - 1);
27
+ String crc = divide(code, key);
28
+
29
+ String transmitted = data + crc;
30
+
31
+ System.out.println("CRC: " + crc);
32
+ System.out.println("Transmitted Data: " + transmitted);
33
+
34
+ System.out.print("Enter received data: ");
35
+ String received = sc.next();
36
+
37
+ String result = divide(received, key);
38
+
39
+ if (result.contains("1"))
40
+ System.out.println("Error Detected!");
41
+ else
42
+ System.out.println("No Error Detected!");
43
+ }
44
+ }
cnkit/texts/p2.txt ADDED
@@ -0,0 +1,32 @@
1
+ import java.util.Scanner;
2
+
3
+ class LeakyBucket {
4
+ public static void main(String[] args) {
5
+ Scanner sc = new Scanner(System.in);
6
+
7
+ int bucketSize = 10;
8
+ int outputRate = 3;
9
+ int water = 0;
10
+
11
+ System.out.print("Enter number of packets: ");
12
+ int n = sc.nextInt();
13
+
14
+ for (int i = 1; i <= n; i++) {
15
+ System.out.print("Enter packet size: ");
16
+ int packet = sc.nextInt();
17
+
18
+ if (water + packet <= bucketSize) {
19
+ water += packet;
20
+ System.out.println("Packet accepted");
21
+ } else {
22
+ System.out.println("Packet dropped");
23
+ }
24
+
25
+ int sent = Math.min(water, outputRate);
26
+ water -= sent;
27
+
28
+ System.out.println("Packets sent: " + sent);
29
+ System.out.println("Remaining packets: " + water);
30
+ }
31
+ }
32
+ }
cnkit/texts/p3.txt ADDED
@@ -0,0 +1,60 @@
1
+ import java.util.*;
2
+
3
+ class BellmanFord {
4
+ public static void main(String[] args) {
5
+ Scanner sc = new Scanner(System.in);
6
+
7
+ System.out.print("Enter number of vertices: ");
8
+ int v = sc.nextInt();
9
+
10
+ System.out.print("Enter number of edges: ");
11
+ int e = sc.nextInt();
12
+
13
+ int[][] edges = new int[e][3];
14
+
15
+ System.out.println("Enter edges (source destination weight):");
16
+ for (int i = 0; i < e; i++) {
17
+ edges[i][0] = sc.nextInt();
18
+ edges[i][1] = sc.nextInt();
19
+ edges[i][2] = sc.nextInt();
20
+ }
21
+
22
+ System.out.print("Enter source vertex: ");
23
+ int src = sc.nextInt();
24
+
25
+ int[] dist = new int[v];
26
+ Arrays.fill(dist, 99999);
27
+ dist[src] = 0;
28
+
29
+ for (int i = 1; i < v; i++) {
30
+ for (int j = 0; j < e; j++) {
31
+ int u = edges[j][0];
32
+ int w = edges[j][1];
33
+ int wt = edges[j][2];
34
+
35
+ if (dist[u] != 99999 &&
36
+ dist[u] + wt < dist[w]) {
37
+ dist[w] = dist[u] + wt;
38
+ }
39
+ }
40
+ }
41
+
42
+ for (int j = 0; j < e; j++) {
43
+ int u = edges[j][0];
44
+ int w = edges[j][1];
45
+ int wt = edges[j][2];
46
+
47
+ if (dist[u] != 99999 &&
48
+ dist[u] + wt < dist[w]) {
49
+ System.out.println("Negative cycle exists!");
50
+ return;
51
+ }
52
+ }
53
+
54
+ System.out.println("Shortest distances:");
55
+
56
+ for (int i = 0; i < v; i++) {
57
+ System.out.println("Vertex " + i + " : " + dist[i]);
58
+ }
59
+ }
60
+ }
cnkit/texts/p4.txt ADDED
@@ -0,0 +1,114 @@
1
+ import java.net.*;
2
+ import java.io.*;
3
+
4
+ class TCPServer {
5
+ public static void main(String[] args) throws Exception {
6
+ ServerSocket ss = new ServerSocket(5000);
7
+
8
+ System.out.println("Server waiting...");
9
+ Socket s = ss.accept();
10
+
11
+ BufferedReader in = new BufferedReader(
12
+ new InputStreamReader(s.getInputStream()));
13
+
14
+ PrintWriter out = new PrintWriter(s.getOutputStream(), true);
15
+
16
+ String msg = in.readLine();
17
+ System.out.println("Client: " + msg);
18
+
19
+ out.println("Message received");
20
+
21
+ s.close();
22
+ ss.close();
23
+ }
24
+ }
25
+
26
+
27
+
28
+ import java.net.*;
29
+ import java.io.*;
30
+
31
+ class TCPClient {
32
+ public static void main(String[] args) throws Exception {
33
+ Socket s = new Socket("localhost", 5000);
34
+
35
+ BufferedReader in = new BufferedReader(
36
+ new InputStreamReader(s.getInputStream()));
37
+
38
+ PrintWriter out = new PrintWriter(s.getOutputStream(), true);
39
+
40
+ out.println("Hello Server");
41
+
42
+ System.out.println("Server: " + in.readLine());
43
+
44
+ s.close();
45
+ }
46
+ }
47
+
48
+
49
+
50
+
51
+ import java.net.*;
52
+
53
+ class UDPServer {
54
+ public static void main(String[] args) throws Exception {
55
+ DatagramSocket ds = new DatagramSocket(6000);
56
+
57
+ byte[] receive = new byte[1024];
58
+
59
+ DatagramPacket dp = new DatagramPacket(
60
+ receive, receive.length);
61
+
62
+ System.out.println("Server waiting...");
63
+ ds.receive(dp);
64
+
65
+ String msg = new String(
66
+ dp.getData(), 0, dp.getLength());
67
+
68
+ System.out.println("Client: " + msg);
69
+
70
+ String reply = "Message received";
71
+ byte[] send = reply.getBytes();
72
+
73
+ DatagramPacket sp = new DatagramPacket(
74
+ send, send.length,
75
+ dp.getAddress(), dp.getPort());
76
+
77
+ ds.send(sp);
78
+ ds.close();
79
+ }
80
+ }
81
+
82
+
83
+
84
+ import java.net.*;
85
+
86
+ class UDPClient {
87
+ public static void main(String[] args) throws Exception {
88
+ DatagramSocket ds = new DatagramSocket();
89
+
90
+ String msg = "Hello Server";
91
+ byte[] send = msg.getBytes();
92
+
93
+ InetAddress ip = InetAddress.getByName("localhost");
94
+
95
+ DatagramPacket dp = new DatagramPacket(
96
+ send, send.length, ip, 6000);
97
+
98
+ ds.send(dp);
99
+
100
+ byte[] receive = new byte[1024];
101
+
102
+ DatagramPacket rp = new DatagramPacket(
103
+ receive, receive.length);
104
+
105
+ ds.receive(rp);
106
+
107
+ String reply = new String(
108
+ rp.getData(), 0, rp.getLength());
109
+
110
+ System.out.println("Server: " + reply);
111
+
112
+ ds.close();
113
+ }
114
+ }
cnkit/texts/p5.txt ADDED
@@ -0,0 +1,43 @@
1
+ import java.util.Scanner;
2
+
3
+ class Network {
4
+ public static void main(String[] args) {
5
+ Scanner sc = new Scanner(System.in);
6
+
7
+ int queueSize, bandwidth;
8
+ int dropped = 0;
9
+
10
+ int[] queue = new int[4];
11
+
12
+ System.out.print("Enter queue size: ");
13
+ queueSize = sc.nextInt();
14
+
15
+ System.out.print("Enter bandwidth: ");
16
+ bandwidth = sc.nextInt();
17
+
18
+ System.out.println("\nThree Node Network:");
19
+ System.out.println("N0 <----> N1 <----> N2");
20
+
21
+ for (int t = 1; t <= 5; t++) {
22
+ System.out.println("\nTime: " + t);
23
+
24
+ for (int i = 0; i < 4; i++) {
25
+ queue[i] += 5;
26
+
27
+ if (queue[i] > queueSize) {
28
+ dropped += queue[i] - queueSize;
29
+ queue[i] = queueSize;
30
+ }
31
+
32
+ int sent = Math.min(queue[i], bandwidth);
33
+ queue[i] -= sent;
34
+
35
+ System.out.println("Link " + i +
36
+ " Sent: " + sent +
37
+ " Remaining: " + queue[i]);
38
+ }
39
+ }
40
+
41
+ System.out.println("\nTotal Packets Dropped: " + dropped);
42
+ }
43
+ }
cnkit/texts/p6.txt ADDED
@@ -0,0 +1,26 @@
1
+ import java.util.Scanner;
2
+
3
+ class NetworkSimulation {
4
+ public static void main(String[] args) {
5
+ Scanner sc = new Scanner(System.in);
6
+
7
+ System.out.print("Enter TCP packet count: ");
8
+ int tcp = sc.nextInt();
9
+
10
+ System.out.print("Enter UDP packet count: ");
11
+ int udp = sc.nextInt();
12
+
13
+ System.out.println("\nNetwork Connections:");
14
+ System.out.println("N0 ---- N2");
15
+ System.out.println("N1 ---- N2");
16
+ System.out.println("N2 ---- N3");
17
+
18
+ System.out.println("\nTCP Connection: N0 to N3");
19
+ System.out.println("UDP Connection: N1 to N3");
20
+
21
+ System.out.println("\nTCP Packets Sent: " + tcp);
22
+ System.out.println("UDP Packets Sent: " + udp);
23
+
24
+ System.out.println("Total Packets Sent: " + (tcp + udp));
25
+ }
26
+ }
cnkit/texts/p7.txt ADDED
@@ -0,0 +1,47 @@
1
+ import java.util.Scanner;
2
+
3
+ class EthernetLAN {
4
+ public static void main(String[] args) {
5
+ Scanner sc = new Scanner(System.in);
6
+
7
+ System.out.print("Enter number of nodes: ");
8
+ int n = sc.nextInt();
9
+
10
+ System.out.print("Enter number of traffic sources: ");
11
+ int flows = sc.nextInt();
12
+
13
+ System.out.print("Enter number of rounds: ");
14
+ int rounds = sc.nextInt();
15
+
16
+ for (int i = 1; i <= flows; i++) {
17
+ System.out.print("\nEnter source node: ");
18
+ int src = sc.nextInt();
19
+
20
+ System.out.print("Enter destination node: ");
21
+ int dest = sc.nextInt();
22
+
23
+ if (src < 0 || dest < 0 || src >= n ||
24
+ dest >= n || src == dest) {
25
+ System.out.println("Invalid nodes!");
26
+ i--;
27
+ continue;
28
+ }
29
+
30
+ int cwnd = 1;
31
+
32
+ System.out.println("\nSource: " + src +
33
+ " Destination: " + dest);
34
+
35
+ for (int j = 1; j <= rounds; j++) {
36
+ System.out.print("Round " + j + ": ");
37
+
38
+ for (int k = 0; k < cwnd; k++)
39
+ System.out.print("*");
40
+
41
+ System.out.println(" CWND = " + cwnd);
42
+
43
+ cwnd = cwnd * 2;
44
+ }
45
+ }
46
+ }
47
+ }
cnkit/texts/p8.txt ADDED
@@ -0,0 +1,45 @@
1
+ import java.util.Scanner;
2
+
3
+ class WirelessLAN {
4
+ public static void main(String[] args) {
5
+ Scanner sc = new Scanner(System.in);
6
+
7
+ System.out.print("Enter number of nodes: ");
8
+ int nodes = sc.nextInt();
9
+
10
+ System.out.print("Enter number of rounds: ");
11
+ int rounds = sc.nextInt();
12
+
13
+ int sent = 0, received = 0, dropped = 0;
14
+
15
+ System.out.println("\nWireless LAN Simulation");
16
+
17
+ for (int i = 1; i <= rounds; i++) {
18
+ System.out.print("Enter transmitting nodes in round "
19
+ + i + ": ");
20
+
21
+ int n = sc.nextInt();
22
+
23
+ sent += n;
24
+
25
+ if (n == 1) {
26
+ received++;
27
+ System.out.println("Packet transmitted successfully");
28
+ } else if (n > 1) {
29
+ dropped += n;
30
+ System.out.println("Collision! Packets dropped");
31
+ } else {
32
+ System.out.println("No transmission");
33
+ }
34
+ }
35
+
36
+ System.out.println("\nTotal Packets Sent: " + sent);
37
+ System.out.println("Packets Received: " + received);
38
+ System.out.println("Packets Dropped: " + dropped);
39
+
40
+ if (sent > 0) {
41
+ double performance = (received * 100.0) / sent;
42
+ System.out.println("Performance: " + performance + "%");
43
+ }
44
+ }
45
+ }