From 140acfd8fc6345745a9b274baaa1e58ea3217f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Rost=C3=A1s?= Date: Tue, 10 Apr 2018 08:56:28 +0200 Subject: [PATCH 1/3] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4415559 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Balázs Rostás + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 8cbeb61380621d55a8b6f8b37632928ca4ed9a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Rost=C3=A1s?= Date: Mon, 6 Sep 2021 16:05:02 +0200 Subject: [PATCH 2/3] Update method to pythonic --- Numbers/prime.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Numbers/prime.py b/Numbers/prime.py index ca622eb..6672a65 100644 --- a/Numbers/prime.py +++ b/Numbers/prime.py @@ -10,7 +10,7 @@ from collections import Counter -def isPrime(x): +def is_prime(x): """ Checks whether the given number x is prime or not @@ -29,7 +29,7 @@ def isPrime(x): return True -def getExponent(n): +def get_exponent(n): """ Counts the same elements in n list returns a list with the exponent of @@ -63,13 +63,13 @@ def main(): # Wrapper function for i in range(counter, n + 1): if n % i == 0: - if isPrime(i): + if is_prime(i): factors.append(i) n //= i break if len(factors) != 0: - factors = getExponent(factors) + factors = get_exponent(factors) print(', '.join(factors)) else: print('The number', n, 'does not have any prime factors.') From 3277b1c407e5cff0a0b8236251a509c67a09fc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Rost=C3=A1s?= Date: Thu, 16 Sep 2021 18:47:29 +0200 Subject: [PATCH 3/3] Update pythonic code style --- Cryptography/Caesar_Cipher.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Cryptography/Caesar_Cipher.py b/Cryptography/Caesar_Cipher.py index 3cbf256..ba8d124 100644 --- a/Cryptography/Caesar_Cipher.py +++ b/Cryptography/Caesar_Cipher.py @@ -3,7 +3,7 @@ MAX_SHIFT = 26 -def whatMode(): +def what_mode(): """ Finds out what the user wants to do """ while True: print("Do you wish to encrypt, decrypt or brute force a message: ") @@ -13,30 +13,30 @@ def whatMode(): else: print("Enter '[E]ncrypt', '[D]ecrypt' or [B]rute") -def plainMessage(): +def plain_message(): """ Gets a string from the user """ print ("Message: ") return input() -def getKey(): +def get_key(): """ Gets a shift value from the user """ - shiftKey = 0 + shift_key = 0 while True: print("Enter shift key (1-%s) " % (MAX_SHIFT)) - shiftKey = int(input()) - if (shiftKey >= 1 and shiftKey <= MAX_SHIFT): - return shiftKey + shift_key = int(input()) + if (shift_key >= 1 and shift_key <= MAX_SHIFT): + return shift_key -def cryptMessage(mode, message, shiftKey): +def crypt_message(mode, message, shift_key): """ The encryption / decryption action is here """ if mode[0] == 'd': - shiftKey = -shiftKey + shift_key = -shift_key translated = '' for symbol in message: # The encryption stuff if symbol.isalpha(): num = ord(symbol) - num += shiftKey + num += shift_key if symbol.isupper(): if num > ord('Z'): @@ -55,16 +55,16 @@ def cryptMessage(mode, message, shiftKey): translated += symbol return translated -mode = whatMode() -message = plainMessage() +mode = what_mode() +message = plain_message() if mode[0] != 'b': - shiftKey = getKey() + shift_key = get_key() print('Your translated text is:') if mode[0] != 'b': #Brute force settings - print(cryptMessage(mode, message, shiftKey)) + print(crypt_message(mode, message, shift_key)) else: - for shiftKey in range(1, MAX_SHIFT + 1): - print(shiftKey, cryptMessage('decrypt', message, shiftKey)) + for shift_key in range(1, MAX_SHIFT + 1): + print(shift_key, crypt_message('decrypt', message, shift_key))