From ab2614574e3e558225db8b00fae886eec06790e3 Mon Sep 17 00:00:00 2001 From: Sergey Tsaplin Date: Mon, 1 Aug 2016 15:06:53 +0500 Subject: [PATCH] Move files to separate directories --- Caesar Cipher.py | 38 ---------------- ciphers/Caesar Cipher.py | 43 +++++++++++++++++++ .../Simple Substitution Cipher.py | 0 .../Transposition Cipher.py | 0 binary_seach.py => searches/binary_search.py | 0 linear_search.py => searches/linear_search.py | 0 bubble_sort.py => sorts/bubble_sort.py | 0 insertion_sort.py => sorts/insertion_sort.py | 0 merge_sort.py => sorts/merge_sort.py | 0 quick_sort.py => sorts/quick_sort.py | 0 selection_sort.py => sorts/selection_sort.py | 0 11 files changed, 43 insertions(+), 38 deletions(-) delete mode 100644 Caesar Cipher.py create mode 100644 ciphers/Caesar Cipher.py rename Simple Substitution Cipher.py => ciphers/Simple Substitution Cipher.py (100%) rename Transposition Cipher.py => ciphers/Transposition Cipher.py (100%) rename binary_seach.py => searches/binary_search.py (100%) rename linear_search.py => searches/linear_search.py (100%) rename bubble_sort.py => sorts/bubble_sort.py (100%) rename insertion_sort.py => sorts/insertion_sort.py (100%) rename merge_sort.py => sorts/merge_sort.py (100%) rename quick_sort.py => sorts/quick_sort.py (100%) rename selection_sort.py => sorts/selection_sort.py (100%) diff --git a/Caesar Cipher.py b/Caesar Cipher.py deleted file mode 100644 index b1342dc5e..000000000 --- a/Caesar Cipher.py +++ /dev/null @@ -1,38 +0,0 @@ -# The Caesar Cipher Algorithm - -message = input("Enter message: ") -key = int(input("Key [1-26]: ")) -mode = input("Encrypt or Decrypt [e/d]: ") - -if mode.lower().startswith('e'): - mode = "encrypt" -elif mode.lower().startswith('d'): - mode = "decrypt" - -LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - -translated = "" - -message = message.upper() - -for symbol in message: - if symbol in LETTERS: - num = LETTERS.find(symbol) - if mode == "encrypt": - num = num + key - elif mode == "decrypt": - num = num - key - - if num >= len(LETTERS): - num = num - len(LETTERS) - elif num < 0: - num = num + len(LETTERS) - - translated = translated + LETTERS[num] - else: - translated = translated + symbol - -if mode == "encrypt": - print("Encryption:", translated) -elif mode == "decrypt": - print("Decryption:", translated) diff --git a/ciphers/Caesar Cipher.py b/ciphers/Caesar Cipher.py new file mode 100644 index 000000000..1689529b7 --- /dev/null +++ b/ciphers/Caesar Cipher.py @@ -0,0 +1,43 @@ +# The Caesar Cipher Algorithm + +def main(): + message = input("Enter message: ") + key = int(input("Key [1-26]: ")) + mode = input("Encrypt or Decrypt [e/d]: ") + + if mode.lower().startswith('e'): + mode = "encrypt" + elif mode.lower().startswith('d'): + mode = "decrypt" + + LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + + translated = "" + + message = message.upper() + + for symbol in message: + if symbol in LETTERS: + num = LETTERS.find(symbol) + if mode == "encrypt": + num = num + key + elif mode == "decrypt": + num = num - key + + if num >= len(LETTERS): + num = num - len(LETTERS) + elif num < 0: + num = num + len(LETTERS) + + translated = translated + LETTERS[num] + else: + translated = translated + symbol + + if mode == "encrypt": + print("Encryption:", translated) + elif mode == "decrypt": + print("Decryption:", translated) + + +if __name__ == '__main__': + main() diff --git a/Simple Substitution Cipher.py b/ciphers/Simple Substitution Cipher.py similarity index 100% rename from Simple Substitution Cipher.py rename to ciphers/Simple Substitution Cipher.py diff --git a/Transposition Cipher.py b/ciphers/Transposition Cipher.py similarity index 100% rename from Transposition Cipher.py rename to ciphers/Transposition Cipher.py diff --git a/binary_seach.py b/searches/binary_search.py similarity index 100% rename from binary_seach.py rename to searches/binary_search.py diff --git a/linear_search.py b/searches/linear_search.py similarity index 100% rename from linear_search.py rename to searches/linear_search.py diff --git a/bubble_sort.py b/sorts/bubble_sort.py similarity index 100% rename from bubble_sort.py rename to sorts/bubble_sort.py diff --git a/insertion_sort.py b/sorts/insertion_sort.py similarity index 100% rename from insertion_sort.py rename to sorts/insertion_sort.py diff --git a/merge_sort.py b/sorts/merge_sort.py similarity index 100% rename from merge_sort.py rename to sorts/merge_sort.py diff --git a/quick_sort.py b/sorts/quick_sort.py similarity index 100% rename from quick_sort.py rename to sorts/quick_sort.py diff --git a/selection_sort.py b/sorts/selection_sort.py similarity index 100% rename from selection_sort.py rename to sorts/selection_sort.py