Skip to content

Commit 55a13d0

Browse files
committed
Innitial commit
1 parent 18575f2 commit 55a13d0

File tree

4,307 files changed

+1084050
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,307 files changed

+1084050
-11
lines changed
Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,57 @@
1+
import networkx as nx
2+
import matplotlib.pyplot as plt
13

2-
# A function to print the factorial of a number
4+
# Create a directed graph
5+
G = nx.DiGraph()
36

4-
def factorial_of_number():
7+
# Define the nodes
8+
nodes = {
9+
"Head Office Router": (0, 4),
10+
"Branch Office Router": (6, 4),
11+
"Head Office Switch": (-1, 2),
12+
"Branch Office Switch": (7, 2),
13+
"Head Office Firewall": (-2, 4),
14+
"Internet": (3, 6),
15+
}
516

6-
number = input("PLease enter the number: ")
7-
number = int(number)
17+
# Define office devices
18+
head_office_devices = ["Admin PC 1", "Admin PC 2", "Printer", "Access Point"]
19+
branch_office_devices = ["Admin PC 3", "Admin PC 4"]
820

9-
fact = 1
21+
# Add all nodes to the graph
22+
G.add_nodes_from(nodes)
1023

11-
for i in range(1, (number+1)):
12-
fact = fact*i
13-
14-
print(f"The factorial of {number} is {fact}")
24+
# Add nodes for devices and connect to respective switches
25+
for i, device in enumerate(head_office_devices):
26+
G.add_node(device)
27+
G.add_edge(device, "Head Office Switch")
1528

16-
# Call the function
17-
factorial_of_number()
29+
for i, device in enumerate(branch_office_devices):
30+
G.add_node(device)
31+
G.add_edge(device, "Branch Office Switch")
32+
33+
# Connect the head office switch to head office router, and branch office switch to branch router
34+
G.add_edge("Head Office Switch", "Head Office Router")
35+
G.add_edge("Branch Office Switch", "Branch Office Router")
36+
37+
# Connect head office router to firewall and firewall to internet
38+
G.add_edge("Head Office Router", "Head Office Firewall")
39+
G.add_edge("Head Office Firewall", "Internet")
40+
41+
# VPN connection from head office to branch office router
42+
G.add_edge("Head Office Router", "Branch Office Router", color="blue", style="dashed")
43+
44+
# Position the main elements and devices around them
45+
pos = nx.spring_layout(G)
46+
pos.update(nodes)
47+
48+
# Draw the nodes and edges
49+
plt.figure(figsize=(10, 8))
50+
nx.draw_networkx_nodes(G, pos, node_color="lightblue", node_size=2000)
51+
nx.draw_networkx_labels(G, pos, font_size=10, font_weight="bold")
52+
nx.draw_networkx_edges(G, pos, edgelist=G.edges(), arrows=True, arrowstyle="-|>", edge_color="black")
53+
54+
# Add legend and title
55+
plt.title("Hybrid Network Topology")
56+
plt.axis("off")
57+
plt.show()
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#
2+
# The Python Imaging Library
3+
# $Id$
4+
#
5+
# bitmap distribution font (bdf) file parser
6+
#
7+
# history:
8+
# 1996-05-16 fl created (as bdf2pil)
9+
# 1997-08-25 fl converted to FontFile driver
10+
# 2001-05-25 fl removed bogus __init__ call
11+
# 2002-11-20 fl robustification (from Kevin Cazabon, Dmitry Vasiliev)
12+
# 2003-04-22 fl more robustification (from Graham Dumpleton)
13+
#
14+
# Copyright (c) 1997-2003 by Secret Labs AB.
15+
# Copyright (c) 1997-2003 by Fredrik Lundh.
16+
#
17+
# See the README file for information on usage and redistribution.
18+
#
19+
20+
"""
21+
Parse X Bitmap Distribution Format (BDF)
22+
"""
23+
from __future__ import annotations
24+
25+
from typing import BinaryIO
26+
27+
from . import FontFile, Image
28+
29+
bdf_slant = {
30+
"R": "Roman",
31+
"I": "Italic",
32+
"O": "Oblique",
33+
"RI": "Reverse Italic",
34+
"RO": "Reverse Oblique",
35+
"OT": "Other",
36+
}
37+
38+
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}
39+
40+
41+
def bdf_char(
42+
f: BinaryIO,
43+
) -> (
44+
tuple[
45+
str,
46+
int,
47+
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]],
48+
Image.Image,
49+
]
50+
| None
51+
):
52+
# skip to STARTCHAR
53+
while True:
54+
s = f.readline()
55+
if not s:
56+
return None
57+
if s[:9] == b"STARTCHAR":
58+
break
59+
id = s[9:].strip().decode("ascii")
60+
61+
# load symbol properties
62+
props = {}
63+
while True:
64+
s = f.readline()
65+
if not s or s[:6] == b"BITMAP":
66+
break
67+
i = s.find(b" ")
68+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
69+
70+
# load bitmap
71+
bitmap = bytearray()
72+
while True:
73+
s = f.readline()
74+
if not s or s[:7] == b"ENDCHAR":
75+
break
76+
bitmap += s[:-1]
77+
78+
# The word BBX
79+
# followed by the width in x (BBw), height in y (BBh),
80+
# and x and y displacement (BBxoff0, BByoff0)
81+
# of the lower left corner from the origin of the character.
82+
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())
83+
84+
# The word DWIDTH
85+
# followed by the width in x and y of the character in device pixels.
86+
dwx, dwy = (int(p) for p in props["DWIDTH"].split())
87+
88+
bbox = (
89+
(dwx, dwy),
90+
(x_disp, -y_disp - height, width + x_disp, -y_disp),
91+
(0, 0, width, height),
92+
)
93+
94+
try:
95+
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
96+
except ValueError:
97+
# deal with zero-width characters
98+
im = Image.new("1", (width, height))
99+
100+
return id, int(props["ENCODING"]), bbox, im
101+
102+
103+
class BdfFontFile(FontFile.FontFile):
104+
"""Font file plugin for the X11 BDF format."""
105+
106+
def __init__(self, fp: BinaryIO) -> None:
107+
super().__init__()
108+
109+
s = fp.readline()
110+
if s[:13] != b"STARTFONT 2.1":
111+
msg = "not a valid BDF file"
112+
raise SyntaxError(msg)
113+
114+
props = {}
115+
comments = []
116+
117+
while True:
118+
s = fp.readline()
119+
if not s or s[:13] == b"ENDPROPERTIES":
120+
break
121+
i = s.find(b" ")
122+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
123+
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
124+
if s.find(b"LogicalFontDescription") < 0:
125+
comments.append(s[i + 1 : -1].decode("ascii"))
126+
127+
while True:
128+
c = bdf_char(fp)
129+
if not c:
130+
break
131+
id, ch, (xy, dst, src), im = c
132+
if 0 <= ch < len(self.glyph):
133+
self.glyph[ch] = xy, dst, src, im

0 commit comments

Comments
 (0)