Skip to content

Commit ab81ff9

Browse files
committed
added files
1 parent 270e68e commit ab81ff9

File tree

8 files changed

+523
-0
lines changed

8 files changed

+523
-0
lines changed

cProblems/nums/bennett.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
void paceCar()
6+
{
7+
char *flag = malloc(28 * sizeof(char));
8+
int arr[28] = {110, 1, 105, 110, 1, 106, 2, 97, 123, 100, 3, 117, 53, 5, 116, 95, 48, 102, 8, 102, 95, 121, 48, 117, 114, 95, 67, 125};
9+
int arrLength = 28;
10+
11+
for (int i = 0; i < arrLength; i++)
12+
{
13+
14+
if (arr[i] <= 10)
15+
{
16+
continue;
17+
}
18+
int *value = arr + i;
19+
char *cast = (char *)value;
20+
strcat(flag, cast);
21+
}
22+
puts(flag);
23+
}
24+
25+
int main()
26+
{
27+
paceCar();
28+
}

cProblems/nums/nums.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
main()
2+
{
3+
int x[] = { 110,
4+
1,
5+
105,
6+
110,
7+
1,
8+
106,
9+
2,
10+
97,
11+
123,
12+
100,
13+
3,
14+
117,
15+
53,
16+
5,
17+
116,
18+
95,
19+
48,
20+
102,
21+
8,
22+
102,
23+
95,
24+
121,
25+
48,
26+
117,
27+
114,
28+
95,
29+
67,
30+
125 } for (int a = 0; a < 28; a++) x[a] > 10 &&
31+
putchar(x[a])
32+
}

pythonProblems/breakthis.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
from datetime import datetime, timedelta
2+
3+
def get_first_day_of_week_after_date(start_date, day_of_week):
4+
#weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
5+
current_date = start_date
6+
while current_date.strftime("%A").lower() != day_of_week.lower():
7+
current_date += timedelta(days=1)
8+
return current_date
9+
10+
def get_all_dates(start_date, end_date, delta_days=7):
11+
all_dates = []
12+
current_date = start_date
13+
while current_date <= end_date:
14+
all_dates.append(current_date)
15+
current_date += timedelta(days=delta_days)
16+
return all_dates
17+
18+
class OfficeHoursScheduler:
19+
def __init__(self, semester_start_date, semester_end_date, ta_schedule):
20+
self.semester_start_date = semester_start_date
21+
self.semester_end_date = semester_end_date
22+
self.office_hours = {} #self.office_hours[person_id][date] = []
23+
"""
24+
Matt:{Jan 10th:[ {10am - 11am},{3pm - 4pm} ]
25+
max:{Jan 11th: [ {11am - 12pm}], Jan 18th: [ {11am - 12pm} ], Jan 25th: [ {11am - 12pm} ]
26+
"""
27+
28+
#add_single_office_hour
29+
def add_single_office_hour(self, person_id, date, start_time, end_time, additional=False):
30+
if person_id not in self.office_hours:
31+
self.office_hours[person_id] = {}
32+
if date not in self.office_hours[person_id]:
33+
self.office_hours[person_id][date] = []
34+
# Check for duplicates before adding
35+
current_office_hours = self.office_hours[person_id][date]
36+
if {'start_time': start_time, 'end_time': end_time} not in current_office_hours:
37+
self.office_hours[person_id][date].append({'start_time': start_time, 'end_time': end_time})
38+
print(f"Added specific office hour for person {person_id} on {date} from {start_time} to {end_time}")
39+
if additional:
40+
pass #add to additional_office_hours list
41+
else:
42+
print(f"Office hour for person {person_id} on {date} at {start_time} to {end_time} already exists")
43+
44+
#add_remaining_office_hours
45+
def add_remaining_office_hours(self, person_id, start_date, day_of_week, start_time, end_time):
46+
date_of_first_office_hours = get_first_day_of_week_after_date(start_date, day_of_week)
47+
for date in get_all_dates(date_of_first_office_hours, self.semester_end_date):
48+
self.add_single_office_hour(person_id, date, start_time, end_time)
49+
50+
def add_office_hours(self, person_id, day_of_week, start_time, end_time):
51+
self.add_remaining_office_hours(person_id, self.semester_start_date, day_of_week, start_time, end_time)
52+
53+
#modify_single_office_hour
54+
def modify_single_office_hour(self, person_id, old_date, old_start_time, old_end_time, new_date, new_start_time, new_end_time):
55+
# Check if person_id exists and has office hours
56+
if person_id in self.office_hours and old_date in self.office_hours[person_id]:
57+
current_office_hours = self.office_hours[person_id][old_date]
58+
for index, office_hour in enumerate(current_office_hours):
59+
if office_hour['start_time'] == old_start_time and office_hour['end_time'] == old_end_time:
60+
# Modify the office hour to new_date, new_start_time, new_end_time
61+
self.office_hours[person_id][old_date][index] = {'start_time': new_start_time, 'end_time': new_end_time}
62+
# Remove the old office hour if new date is different
63+
if old_date != new_date:
64+
self.office_hours[person_id][new_date] = self.office_hours[person_id].get(new_date, [])
65+
self.office_hours[person_id][new_date].append({'start_time': new_start_time, 'end_time': new_end_time})
66+
del self.office_hours[person_id][old_date][index]
67+
if not self.office_hours[person_id][old_date]:
68+
del self.office_hours[person_id][old_date]
69+
return True # Successfully modified the office hour
70+
return False # Unable to modify the office hour
71+
72+
#modify_remaining_office_hours
73+
#
74+
"""
75+
def modify_remaining_office_hours(modify_single_office_hour(self, person_id, start_date, old_start_time, old_end_time, new_day_of_week, new_start_time, new_end_time))
76+
date_of_first_office_hours = get_first_day_of_week_after_date(start_date, old_day_of_week)
77+
for date in get_all_dates(date_of_first_office_hours, self.semester_end_date):
78+
self.modify_single_office_hour(person_id, date, old_start_time, old_end_time, new_date, new_start_time, new_end_time):
79+
"""
80+
#modify_office_hours
81+
82+
#remove_single_office_hour
83+
def remove_single_office_hour(self, person_id, date, start_time, end_time):
84+
if person_id in self.office_hours and date in self.office_hours[person_id]:
85+
current_office_hours = self.office_hours[person_id][date]
86+
for index, office_hour in enumerate(current_office_hours):
87+
if office_hour['start_time'] == start_time and office_hour['end_time'] == end_time:
88+
del self.office_hours[person_id][date][index]
89+
if not self.office_hours[person_id][date]:
90+
del self.office_hours[person_id][date]
91+
return True # Successfully removed the office hour
92+
return False # Unable to remove the office hour
93+
94+
#remove_remaining_office_hours
95+
def remove_remaining_office_hours(self, person_id, start_date, day_of_week, start_time, end_time):
96+
current_date = start_date
97+
while current_date <= self.semester_end_date:
98+
if current_date.weekday() == day_of_week:
99+
self.remove_single_office_hour(person_id, current_date, start_time, end_time)
100+
current_date += timedelta(days=1)
101+
#remove_office_hours # self, person_id, date, start_time, end_time, additional=False):
102+
def remove_office_hours(self, person_id, day_of_week, start_time, end_time):
103+
self.remove_remaining_office_hours( person_id, self.semester_start, day_of_week, start_time, end_time)
104+
def pretty_print_office_hours(self):
105+
for person_id, person_schedule in self.office_hours.items():
106+
print(person_schedule)
107+
for date, office_hours in person_schedule.items():
108+
print(f"\tDate: {date.strftime('%Y-%m-%d')}")
109+
print("\tOffice Hours:")
110+
for hour in office_hours:
111+
print(f"\t\tStart Time: {hour['start_time']} - End Time: {hour['end_time']}")
112+
113+
# Example usage:
114+
semester_start = datetime(2024, 1, 3)
115+
semester_end = datetime(2024, 5, 31)
116+
ta_schedule = {'day_of_week': 'Monday', 'start_time': '09:00 AM', 'end_time': '11:00 AM'}
117+
118+
scheduler = OfficeHoursScheduler(semester_start, semester_end, ta_schedule)
119+
120+
#Assignment Example:
121+
scheduler.add_office_hours('Matt', 'Thursday', '10:00 AM', '11:00 AM')
122+
123+
try:
124+
scheduler.add_single_office_hour('Max', None, '11:00 AM', '12:00 PM')
125+
scheduler.add_single_office_hour('Max', None, '11:00 AM', '12:00 PM')
126+
scheduler.add_single_office_hour('Max', None, '11:00 AM', '12:00 PM')
127+
except:
128+
print("Classic None")
129+
130+
# try:
131+
# scheduler.add_single_office_hour('Max', datetime(0, 0, 0), '11:00 AM', '12:00 PM')
132+
# scheduler.add_single_office_hour('Max', datetime(0, 0, 0), '11:00 AM', '12:00 PM')
133+
# scheduler.add_single_office_hour('Max', datetime(0, 0, 0), '11:00 AM', '12:00 PM')
134+
# except:
135+
# print("Classic None")
136+
137+
# scheduler.modify_single_office_hour('Matt', datetime(2024, 1, 4), '10:00 AM', '11:00 AM', datetime(2024, 1, 5), '6:00 PM', '7:00 PM')
138+
139+
140+
print(scheduler.pretty_print_office_hours())
141+
#scheduler.add_office_hour(1, datetime(2024, 1, 10), '09:00 AM', '11:00 AM') #next Wednesday
142+
#scheduler.add_office_hour(1, datetime(2024, 1, 12), '10:00 AM', '12:00 PM') #next Fridat
143+
#scheduler.modify_office_hour(1, datetime(2024, 1, 10), '10:00 AM', '12:00 PM')
144+
#scheduler.remove_office_hour(1, datetime(2024, 1, 10))
145+
#scheduler.remove_remaining_office_hours(1, datetime(2024, 1, 10))
146+
#scheduler.modify_remaining_office_hours(1, datetime(2024, 1, 10), '01:00 PM', '03:00 PM')

pythonProblems/l4ugh/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM php:8.2-apache
2+
3+
RUN apt-get update && apt -y install mariadb-server && apt-get install -y libpng-dev python3 python3-pip libfontconfig nano
4+
RUN docker-php-ext-install mysqli
5+
COPY src /var/www/html/
6+
COPY app.py /
7+
RUN pip3 install pip==22.3.1 --break-system-packages
8+
RUN pip3 install mysql-connector-python flask
9+
COPY init.sh /
10+
COPY init.db /
11+
RUN chmod +x /init.sh
12+
EXPOSE 80
13+
ENTRYPOINT [ "/bin/bash", "/init.sh"]

pythonProblems/l4ugh/app.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from flask import Flask, request
2+
import mysql.connector
3+
import hashlib
4+
5+
app = Flask(__name__)
6+
7+
# MySQL connection configuration
8+
mysql_host = "127.0.0.1"
9+
mysql_user = "root"
10+
mysql_password = "root"
11+
mysql_db = "ctf"
12+
13+
14+
def authenticate_user(username, password):
15+
try:
16+
conn = mysql.connector.connect(
17+
host=mysql_host,
18+
user=mysql_user,
19+
password=mysql_password,
20+
database=mysql_db
21+
)
22+
23+
cursor = conn.cursor()
24+
25+
query = "SELECT * FROM users WHERE username = %s AND password = %s"
26+
cursor.execute(query, (username, password))
27+
28+
result = cursor.fetchone()
29+
30+
cursor.close()
31+
conn.close()
32+
33+
return result
34+
except mysql.connector.Error as error:
35+
print("Error while connecting to MySQL", error)
36+
return None
37+
38+
39+
@app.route('/login', methods=['POST'])
40+
def handle_request():
41+
try:
42+
username = request.form.get('username')
43+
password = hashlib.md5(request.form.get(
44+
'password').encode()).hexdigest()
45+
# Authenticate user
46+
user_data = authenticate_user(username, password)
47+
48+
if user_data:
49+
return "0xL4ugh{Test_Flag}"
50+
else:
51+
return "Invalid credentials"
52+
except:
53+
return "internal error happened"
54+
55+
56+
if __name__ == '__main__':
57+
app.run(host='0.0.0.0', port=5000, debug=True)

pythonProblems/l4ugh/init.db

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
--
3+
-- Database: `CTF`
4+
--
5+
CREATE DATABASE IF NOT EXISTS `CTF` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
6+
USE `CTF`;
7+
8+
-- --------------------------------------------------------
9+
10+
11+
12+
--
13+
-- Table structure for table `users`
14+
--
15+
16+
DROP TABLE IF EXISTS `users`;
17+
CREATE TABLE IF NOT EXISTS `users` (
18+
`id` varchar(50) NOT NULL,
19+
`username` varchar(20) NOT NULL,
20+
`password` varchar(50) NOT NULL
21+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=66 ;
22+
23+
24+
25+
26+
insert into users(id,username,password) values('1','admin','21232f297a57a5a743894a0e4a801fc3');
27+

pythonProblems/l4ugh/init.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
service mariadb start && service apache2 start
3+
USER="root"
4+
PASSWORD="root"
5+
6+
echo "Creating new user ${MYSQL_USER} ..."
7+
mysql -uroot -e "CREATE USER '${USER}'@'localhost' IDENTIFIED BY '${PASSWORD}';"
8+
echo "Granting privileges..."
9+
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${USER}'@'localhost';"
10+
mysql -uroot -e "GRANT FILE ON *.* TO '${USER}'@'localhost';"
11+
mysql -uroot -e "FLUSH PRIVILEGES;"
12+
echo "Done! Permissions granted"
13+
mysql -u$USER -p$PASSWORD -e "CREATE database CTF;"
14+
mysql -u$USER -p$PASSWORD CTF < /init.db
15+
echo "All done."
16+
sleep 5
17+
python3 -u /app.py

0 commit comments

Comments
 (0)