mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-19 08:47:01 +00:00
Merge pull request #46 from Henocks/patch-2
Slight Performance/Visual Update
This commit is contained in:
commit
3f505c5b39
|
@ -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__':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user