mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Make some ruff fixes (#8154)
* Make some ruff fixes * Undo manual fix * Undo manual fix * Updates from ruff=0.0.251
This commit is contained in:
@@ -33,7 +33,7 @@ class BifidCipher:
|
||||
>>> np.array_equal(BifidCipher().letter_to_numbers('u'), [4,5])
|
||||
True
|
||||
"""
|
||||
index1, index2 = np.where(self.SQUARE == letter)
|
||||
index1, index2 = np.where(letter == self.SQUARE)
|
||||
indexes = np.concatenate([index1 + 1, index2 + 1])
|
||||
return indexes
|
||||
|
||||
|
||||
@@ -228,10 +228,10 @@ class DiffieHellman:
|
||||
|
||||
def is_valid_public_key(self, key: int) -> bool:
|
||||
# check if the other public key is valid based on NIST SP800-56
|
||||
if 2 <= key and key <= self.prime - 2:
|
||||
if pow(key, (self.prime - 1) // 2, self.prime) == 1:
|
||||
return True
|
||||
return False
|
||||
return (
|
||||
2 <= key <= self.prime - 2
|
||||
and pow(key, (self.prime - 1) // 2, self.prime) == 1
|
||||
)
|
||||
|
||||
def generate_shared_key(self, other_key_str: str) -> str:
|
||||
other_key = int(other_key_str, base=16)
|
||||
@@ -243,10 +243,10 @@ class DiffieHellman:
|
||||
@staticmethod
|
||||
def is_valid_public_key_static(remote_public_key_str: int, prime: int) -> bool:
|
||||
# check if the other public key is valid based on NIST SP800-56
|
||||
if 2 <= remote_public_key_str and remote_public_key_str <= prime - 2:
|
||||
if pow(remote_public_key_str, (prime - 1) // 2, prime) == 1:
|
||||
return True
|
||||
return False
|
||||
return (
|
||||
2 <= remote_public_key_str <= prime - 2
|
||||
and pow(remote_public_key_str, (prime - 1) // 2, prime) == 1
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def generate_shared_key_static(
|
||||
|
||||
@@ -31,7 +31,7 @@ class PolybiusCipher:
|
||||
>>> np.array_equal(PolybiusCipher().letter_to_numbers('u'), [4,5])
|
||||
True
|
||||
"""
|
||||
index1, index2 = np.where(self.SQUARE == letter)
|
||||
index1, index2 = np.where(letter == self.SQUARE)
|
||||
indexes = np.concatenate([index1 + 1, index2 + 1])
|
||||
return indexes
|
||||
|
||||
|
||||
@@ -128,11 +128,10 @@ class XORCipher:
|
||||
assert isinstance(file, str) and isinstance(key, int)
|
||||
|
||||
try:
|
||||
with open(file) as fin:
|
||||
with open("encrypt.out", "w+") as fout:
|
||||
# actual encrypt-process
|
||||
for line in fin:
|
||||
fout.write(self.encrypt_string(line, key))
|
||||
with open(file) as fin, open("encrypt.out", "w+") as fout:
|
||||
# actual encrypt-process
|
||||
for line in fin:
|
||||
fout.write(self.encrypt_string(line, key))
|
||||
|
||||
except OSError:
|
||||
return False
|
||||
@@ -152,11 +151,10 @@ class XORCipher:
|
||||
assert isinstance(file, str) and isinstance(key, int)
|
||||
|
||||
try:
|
||||
with open(file) as fin:
|
||||
with open("decrypt.out", "w+") as fout:
|
||||
# actual encrypt-process
|
||||
for line in fin:
|
||||
fout.write(self.decrypt_string(line, key))
|
||||
with open(file) as fin, open("decrypt.out", "w+") as fout:
|
||||
# actual encrypt-process
|
||||
for line in fin:
|
||||
fout.write(self.decrypt_string(line, key))
|
||||
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user