Skip to content

Commit 22f3243

Browse files
authored
Merge pull request #1 from geekcomputers/master
Updated from orignal
2 parents bcca248 + a072dd7 commit 22f3243

File tree

9 files changed

+256
-33
lines changed

9 files changed

+256
-33
lines changed

CRC/crc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def crc_check(data, div):
3434
data = data + ("0" * (len(div) - 1))
3535
crc = crc_check(data, div)
3636
crc_str = ""
37-
for i in range(len(crc)):
38-
crc_str += str(crc[i])
37+
for c in crc:
38+
crc_str += c
3939
print("Sent data: ", original_data + crc_str)
4040
sent_data = original_data + crc_str
4141
print("If again applying CRC algorithm, the remainder/CRC must be zero if errorless.")

Digital Clock/digital_clock.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def dig_clock():
2121
# to update the time display as needed
2222
# could use >200 ms, but display gets jerky
2323

24-
label.after(200, clack)
24+
Heart-Turtle
25+
label.after(200, dig_clock)
26+
=======
27+
label.after(200, dig_clock)
28+
master
2529

2630
dig_clock()
2731

EncryptionTool.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ def decryptChar(target):
2929

3030
def encrypt(input_text):
3131
col_values = []
32-
for i in range(len(input_text)):
33-
current = ord(input_text[i])
32+
for inp in input_text:
33+
current = ord(inp)
3434
current = encryptChar(current)
3535
col_values.append(current)
3636
return col_values
3737

3838

3939
def decrypt(enc_text):
4040
col_values = []
41-
for i in range(len(enc_text)):
42-
current = int(decryptChar(enc_text[i]))
41+
for enc in enc_text:
42+
current = int(decryptChar(enc))
4343
current = chr(current)
4444
col_values.append(current)
4545
return col_values
@@ -52,9 +52,9 @@ def readAndDecrypt(filename):
5252
actualdata = []
5353
datalist = data.split(" ")
5454
datalist.remove('')
55-
datalistint = [float(datalist[i]) for i in range(len(datalist))]
56-
for i in range(len(datalist)):
57-
current1 = int(decryptChar(datalistint[i]))
55+
datalistint = [float(data) for data in datalist]
56+
for data in datalist:
57+
current1 = int(decryptChar(data))
5858
current1 = chr(current1)
5959
actualdata.append(current1)
6060
file.close()
@@ -67,8 +67,8 @@ def readAndEncrypt(filename):
6767
datalist = list(data)
6868
encrypted_list = list()
6969
encrypted_list_str = list()
70-
for i in range(len(datalist)):
71-
current = ord(datalist[i])
70+
for data in datalist:
71+
current = ord(data)
7272
current = encryptChar(current)
7373
encrypted_list.append(current)
7474
file.close()
@@ -78,36 +78,36 @@ def readAndEncrypt(filename):
7878
def readAndEncryptAndSave(inp_file, out_file):
7979
enc_list = readAndEncrypt(inp_file)
8080
output = open(out_file, "w")
81-
for i in range(len(enc_list)):
82-
output.write(str(enc_list[i]) + " ")
81+
for enc in enc_list:
82+
output.write(str(enc) + " ")
8383
output.close()
8484

8585

8686
def readAndDecryptAndSave(inp_file, out_file):
8787
dec_list = readAndDecrypt(inp_file)
8888
output = open(out_file, "w")
89-
for i in range(len(dec_list)):
90-
output.write(str(dec_list[i]))
89+
for dec in dec_list:
90+
output.write(str(dec))
9191
output.close()
9292

9393

9494
# encryption
95-
for i in range(len(text)):
96-
current = ord(text[i])
95+
for t in text:
96+
current = ord(t)
9797
current = encryptChar(current)
9898
values.append(current)
9999

100100
# decryption
101-
for i in range(len(text)):
102-
current = int(decryptChar(values[i]))
101+
for v in values:
102+
current = int(decryptChar(v))
103103
current = chr(current)
104104
reverse.append(current)
105105
print(reverse)
106106

107107
# saves encrypted in txt file
108108
output = open("encrypted.txt", "w")
109-
for i in range(len(values)):
110-
output.write(str(values[i]) + " ")
109+
for v in values:
110+
output.write(str(v) + " ")
111111
output.close()
112112

113113
# read and decrypts

Password Generator/pass_gen.py

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,84 @@
1-
'''
2-
The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords,
3-
account authentication, security tokens, and related secrets.
4-
'''
5-
import string
1+
import string as str
62
import secrets
73

8-
def secure_password_gen(passlength):
9-
password = ''.join((secrets.choice(string.ascii_letters) for i in range(passlength)))
10-
return password
4+
class PasswordGenerator():
115

12-
n = int(input('Enter length of password : '))
13-
print('Password generated is :', secure_password_gen(n))
6+
@staticmethod
7+
def gen_sequence(conditions): #must have conditions (in a list format), for each member of the list possible_characters
8+
possible_characters=[str.ascii_lowercase, str.ascii_uppercase, str.digits, str.punctuation]
9+
sequence=""
10+
for x in range(len(conditions)):
11+
if conditions[x]:
12+
sequence+=possible_characters[x]
13+
else:
14+
pass
15+
return sequence
16+
17+
18+
@staticmethod
19+
def gen_password(sequence, passlength=8):
20+
password = ''.join((secrets.choice(sequence) for i in range(passlength)))
21+
return password
22+
23+
24+
class Interface():
25+
has_characters={
26+
"lowercase":True,
27+
"uppercase":True,
28+
"digits":True,
29+
"punctuation":True
30+
}
31+
@classmethod
32+
def change_has_characters(cls, change):
33+
try:
34+
cls.has_characters[change] #to check if the specified key exists in the dicitonary
35+
except:
36+
print("Invalid")
37+
else:
38+
cls.has_characters[change]= not cls.has_characters[change] #automaticly changres to the oppesite value already there
39+
print(f"{change} is now set to {cls.has_characters[change]}")
40+
@classmethod
41+
def show_has_characters(cls):
42+
print(cls.has_characters)
43+
44+
45+
def generate_password(self, lenght):
46+
sequence = PasswordGenerator.gen_sequence(list(self.has_characters.values()))
47+
print(PasswordGenerator.gen_password(sequence, lenght))
48+
49+
def list_to_vertical_string(list):
50+
to_return =""
51+
for member in list:
52+
to_return += f"{member}\n"
53+
return to_return
54+
55+
class Run():
56+
def decide_operation(self):
57+
user_input = input(": ")
58+
try:
59+
int(user_input)
60+
except:
61+
Interface.change_has_characters(user_input)
62+
else:
63+
Interface().generate_password(int(user_input))
64+
finally:
65+
print("\n\n")
66+
67+
68+
69+
def run(self):
70+
menu = \
71+
f"""Welcome to the PassGen App!
72+
Commands:
73+
generate password ->
74+
<lenght of the password>
75+
76+
commands to change the characters to be used to generate passwords:
77+
{list_to_vertical_string(Interface.has_characters.keys())}
78+
"""
79+
print(menu)
80+
while True:
81+
self.decide_operation()
82+
83+
84+
Run().run()

Sorting Algorithims/Tim_sort.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
''' Author : Mohit Kumar
2+
3+
Tim Sort implemented in python
4+
Time Complexity : O(n log(n))
5+
Space Complexity :O(n)
6+
7+
'''
8+
9+
# Python3 program to perform TimSort.
10+
RUN = 32
11+
12+
# This function sorts array from left index to
13+
# to right index which is of size atmost RUN
14+
def insertionSort(arr, left, right):
15+
16+
for i in range(left + 1, right+1):
17+
18+
temp = arr[i]
19+
j = i - 1
20+
while j >= left and arr[j] > temp :
21+
22+
arr[j+1] = arr[j]
23+
j -= 1
24+
25+
arr[j+1] = temp
26+
27+
# merge function merges the sorted runs
28+
def merge(arr, l, m, r):
29+
30+
# original array is broken in two parts
31+
# left and right array
32+
len1, len2 = m - l + 1, r - m
33+
left, right = [], []
34+
for i in range(0, len1):
35+
left.append(arr[l + i])
36+
for i in range(0, len2):
37+
right.append(arr[m + 1 + i])
38+
39+
i, j, k = 0, 0, l
40+
# after comparing, we merge those two array
41+
# in larger sub array
42+
while i < len1 and j < len2:
43+
44+
if left[i] <= right[j]:
45+
arr[k] = left[i]
46+
i += 1
47+
48+
else:
49+
arr[k] = right[j]
50+
j += 1
51+
52+
k += 1
53+
54+
# copy remaining elements of left, if any
55+
while i < len1:
56+
57+
arr[k] = left[i]
58+
k += 1
59+
i += 1
60+
61+
# copy remaining element of right, if any
62+
while j < len2:
63+
arr[k] = right[j]
64+
k += 1
65+
j += 1
66+
67+
# iterative Timsort function to sort the
68+
# array[0...n-1] (similar to merge sort)
69+
def timSort(arr, n):
70+
71+
# Sort individual subarrays of size RUN
72+
for i in range(0, n, RUN):
73+
insertionSort(arr, i, min((i+31), (n-1)))
74+
75+
# start merging from size RUN (or 32). It will merge
76+
# to form size 64, then 128, 256 and so on ....
77+
size = RUN
78+
while size < n:
79+
80+
# pick starting point of left sub array. We
81+
# are going to merge arr[left..left+size-1]
82+
# and arr[left+size, left+2*size-1]
83+
# After every merge, we increase left by 2*size
84+
for left in range(0, n, 2*size):
85+
86+
# find ending point of left sub array
87+
# mid+1 is starting point of right sub array
88+
mid = left + size - 1
89+
right = min((left + 2*size - 1), (n-1))
90+
91+
# merge sub array arr[left.....mid] &
92+
# arr[mid+1....right]
93+
merge(arr, left, mid, right)
94+
95+
size = 2*size
96+
97+
# utility function to print the Array
98+
def printArray(arr, n):
99+
100+
for i in range(0, n):
101+
print(arr[i], end = " ")
102+
print()
103+
104+
if __name__ == "__main__":
105+
106+
n = int(input('Enter size of array\n'))
107+
print('Enter elements of array\n')
108+
109+
arr = list(map(int ,input().split()))
110+
print("Given Array is")
111+
printArray(arr, n)
112+
113+
timSort(arr, n)
114+
115+
print("After Sorting Array is")
116+
printArray(arr, n)
117+
118+
'''
119+
OUTPUT :
120+
121+
Enter size of array : 5
122+
Given Array is
123+
5 3 4 2 1
124+
After Sorting Array is
125+
1 2 3 4 5
126+
127+
'''
128+

bankmanaging.db

16 KB
Binary file not shown.

data.db

Whitespace-only changes.

helloworld.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# in c -> printf("Hello World!");
55
# in java -> System.out.println("Hello World!");
66
# in c++ -> cout << "Hello World";
7-
# in javascript - > console.log("Hello World");
7+
# in javascript - > console.log("Hello World");

love_turtle.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import turtle
2+
t= turtle.Turtle()
3+
turtle.title("I Love You")
4+
screen= turtle.Screen()
5+
screen.bgcolor("white")
6+
t.color("red")
7+
t.begin_fill()
8+
t.fillcolor("black")
9+
10+
t.left(140)
11+
t.forward(180)
12+
t.circle(-90, 200)
13+
14+
t.setheading(60) # t.left
15+
t.circle(-90, 200)
16+
t.forward(180)
17+
18+
t.end_fill()
19+
t.hideturtle()
20+

0 commit comments

Comments
 (0)