Skip to content

Sourcery refactored master branch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 28, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from SKAUL05 June 28, 2023 12:56
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -73 to -77
x = retroactive_resolution(
return retroactive_resolution(
augmented_mat[:, 0:columns], augmented_mat[:, columns : columns + 1]
)

return x
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gaussian_elimination refactored with the following changes:

y = []
for i in range(n):
y.append([])
y = [[] for _ in range(n)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

for i in range(0, repeats):
for _ in range(0, repeats):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SecantMethod refactored with the following changes:

create_state_space_tree(sequence, [], 0, [0 for i in range(len(sequence))])
create_state_space_tree(sequence, [], 0, [0 for _ in range(len(sequence))])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generate_all_permutations refactored with the following changes:

Comment on lines -35 to +38
for i, j in zip(range(row, -1, -1), range(column, len(board))):
if board[i][j] == 1:
return False
return True
return all(
board[i][j] != 1
for i, j in zip(range(row, -1, -1), range(column, len(board)))
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function isSafe refactored with the following changes:

i = 0
while i < len(s):
for i in range(0, len(s), 3):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function encode_base64 refactored with the following changes:

Comment on lines -52 to +61
else:
if i == "=":
c += "="
elif i == "=":
c += "="

p = ""
if c == "=":
p = "A"
else:
if c == "==":
p = "AA"
elif c == "==":
p = "AA"

r = b""
s = s + p

i = 0
while i < len(s):
for i in range(0, len(s), 4):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function decode_base64 refactored with the following changes:

Comment on lines -37 to +43
num = num - key
num -= key
if num < 0:
num = num + len(LETTERS)
translated = translated + LETTERS[num]
else:
translated = translated + symbol
print("Decryption using Key #%s: %s" % (key, translated))
print(f"Decryption using Key #{key}: {translated}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function decrypt refactored with the following changes:

Comment on lines -26 to +27
key = 1
result = ""
while key <= 94:
for key in range(1, 95):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function brute_force refactored with the following changes:

Comment on lines -44 to +45
if os.path.exists("%s_pubkey.txt" % name) or os.path.exists(
"%s_privkey.txt" % name
if os.path.exists(f"{name}_pubkey.txt") or os.path.exists(
f"{name}_privkey.txt"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makeKeyFiles refactored with the following changes:

if a == 0:
return b
return gcd(b % a, a)
return b if a == 0 else gcd(b % a, a)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gcd refactored with the following changes:

Comment on lines -117 to +122
det_inv = None
for i in range(len(self.key_string)):
if (det * i) % len(self.key_string) == 1:
det_inv = i
break

det_inv = next(
(
i
for i in range(len(self.key_string))
if (det * i) % len(self.key_string) == 1
),
None,
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HillCipher.makeDecryptKey refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)

for i in range(N):
for _ in range(N):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

dic = dict()
dic = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function mixed_keyword refactored with the following changes:

Comment on lines -53 to +56
cipher = ""
for letter in message:
if letter != " ":

cipher += MORSE_CODE_DICT[letter] + " "
else:

cipher += " "

return cipher
return "".join(
f"{MORSE_CODE_DICT[letter]} " if letter != " " else " "
for letter in message
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function encrypt refactored with the following changes:

password = [random.choice(choices) for i in range(random.randint(10, 20))]
return password
return [random.choice(choices) for _ in range(random.randint(10, 20))]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ShuffledShiftCipher.__passcode_creator refactored with the following changes:

Comment on lines -24 to +25
keyList = list(key)
lettersList = list(LETTERS)
keyList.sort()
keyList = sorted(key)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function checkValidKey refactored with the following changes:

tmp = []

for character in messagePart:
tmp.append(character2Number[character])

tmp = [character2Number[character] for character in messagePart]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function __encryptPart refactored with the following changes:

decrypted = ""

for i in range(0, len(message) + 1, period):
a, b, c = __decryptPart(message[i : i + period], character2Number)

for j in range(0, len(a)):
decrypted_numeric.append(a[j] + b[j] + c[j])

for each in decrypted_numeric:
decrypted += number2Character[each]

return decrypted
decrypted_numeric.extend(a[j] + b[j] + c[j] for j in range(0, len(a)))
return "".join(number2Character[each] for each in decrypted_numeric)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function decryptMessage refactored with the following changes:

Comment on lines -120 to +109
print("Encrypted: {}\nDecrypted: {}".format(encrypted, decrypted))
print(f"Encrypted: {encrypted}\nDecrypted: {decrypted}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 120-120 refactored with the following changes:

key = int(input("Enter key [2-%s]: " % (len(message) - 1)))
key = int(input(f"Enter key [2-{len(message) - 1}]: "))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

Comment on lines -12 to +15
print("File %s does not exist. Quitting..." % inputFile)
print(f"File {inputFile} does not exist. Quitting...")
sys.exit()
if os.path.exists(outputFile):
print("Overwrite %s? [y/n]" % outputFile)
print(f"Overwrite {outputFile}? [y/n]")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

# This will be returned
ans = []

for ch in content:
ans.append(chr(ord(ch) ^ key))

return ans
return [chr(ord(ch) ^ key) for ch in content]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function XORCipher.encrypt refactored with the following changes:

This removes the following comments ( why? ):

# This will be returned

Comment on lines -73 to +67
# This will be returned
ans = []

for ch in content:
ans.append(chr(ord(ch) ^ key))

return ans
return [chr(ord(ch) ^ key) for ch in content]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function XORCipher.decrypt refactored with the following changes:

This removes the following comments ( why? ):

# This will be returned

Comment on lines -98 to +86
# This will be returned
ans = ""

for ch in content:
ans += chr(ord(ch) ^ key)

return ans
return "".join(chr(ord(ch) ^ key) for ch in content)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function XORCipher.encrypt_string refactored with the following changes:

This removes the following comments ( why? ):

# This will be returned

Comment on lines -29 to +31
else:
depth_l_tree = depth_of_tree(tree.left)
depth_r_tree = depth_of_tree(tree.right)
if depth_l_tree > depth_r_tree:
return 1 + depth_l_tree
else:
return 1 + depth_r_tree
depth_l_tree = depth_of_tree(tree.left)
depth_r_tree = depth_of_tree(tree.right)
return 1 + depth_l_tree if depth_l_tree > depth_r_tree else 1 + depth_r_tree
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function depth_of_tree refactored with the following changes:

Comment on lines -73 to +96
if not self.empty():
# Look for the node with that label
node = self.getNode(label)
# If the node exists
if node is not None:
# If it has no children
if node.getLeft() is None and node.getRight() is None:
self.__reassignNodes(node, None)
node = None
# Has only right children
elif node.getLeft() is None and node.getRight() is not None:
self.__reassignNodes(node, node.getRight())
# Has only left children
elif node.getLeft() is not None and node.getRight() is None:
self.__reassignNodes(node, node.getLeft())
# Has two children
else:
# Gets the max value of the left branch
tmpNode = self.getMax(node.getLeft())
# Deletes the tmpNode
self.delete(tmpNode.getLabel())
# Assigns the value to the node to delete and keesp tree structure
node.setLabel(tmpNode.getLabel())
if self.empty():
return
# Look for the node with that label
node = self.getNode(label)
# If the node exists
if node is not None:
# If it has no children
if node.getLeft() is None and node.getRight() is None:
self.__reassignNodes(node, None)
node = None
# Has only right children
elif node.getLeft() is None and node.getRight() is not None:
self.__reassignNodes(node, node.getRight())
# Has only left children
elif node.getLeft() is not None and node.getRight() is None:
self.__reassignNodes(node, node.getLeft())
# Has two children
else:
# Gets the max value of the left branch
tmpNode = self.getMax(node.getLeft())
# Deletes the tmpNode
self.delete(tmpNode.getLabel())
# Assigns the value to the node to delete and keesp tree structure
node.setLabel(tmpNode.getLabel())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinarySearchTree.delete refactored with the following changes:

Comment on lines -116 to +117
if root is not None:
curr_node = root
else:
# We go deep on the right branch
curr_node = self.getRoot()
curr_node = root if root is not None else self.getRoot()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinarySearchTree.getMax refactored with the following changes:

This removes the following comments ( why? ):

# We go deep on the right branch

Comment on lines -127 to +124
if root is not None:
curr_node = root
else:
# We go deep on the left branch
curr_node = self.getRoot()
curr_node = root if root is not None else self.getRoot()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinarySearchTree.getMin refactored with the following changes:

This removes the following comments ( why? ):

# We go deep on the left branch

Comment on lines -139 to +132
if self.root is None:
return True
return False
return self.root is None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinarySearchTree.empty refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants