Slight Performance/Visual Update

This commit is contained in:
Henocks 2016-11-09 23:17:04 +09:00 committed by GitHub
parent 18afe45e4a
commit 43513803f0

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__':