Merge pull request #46 from Henocks/patch-2

Slight Performance/Visual Update
This commit is contained in:
Harshil 2016-11-09 19:55:27 +05:30 committed by GitHub
commit 3f505c5b39

View File

@ -17,13 +17,6 @@ def main():
print("Decryption:", translated) print("Decryption:", translated)
def encdec(message, key, mode): def encdec(message, key, mode):
"""
>>> encdec('Harshil Darji', 12, 'encrypt')
'TMDETUX PMDVU'
>>> encdec('TMDETUX PMDVU', 12, 'decrypt')
'HARSHIL DARJI'
"""
message = message.upper() message = message.upper()
translated = "" translated = ""
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@ -36,13 +29,13 @@ def encdec(message, key, mode):
num = num - key num = num - key
if num >= len(LETTERS): if num >= len(LETTERS):
num = num - len(LETTERS) num -= len(LETTERS)
elif num < 0: elif num < 0:
num = num + len(LETTERS) num += len(LETTERS)
translated = translated + LETTERS[num] translated += LETTERS[num]
else: else:
translated = translated + symbol translated += symbol
return translated return translated
if __name__ == '__main__': if __name__ == '__main__':