mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-17 03:07:35 +00:00
Fix:Used list instead of string in rot13.py and removed n
This commit is contained in:
parent
3e9ca92ca9
commit
1ff77c1612
@ -1,4 +1,4 @@
|
|||||||
def dencrypt(s: str, n: int = 13) -> str:
|
def dencrypt(s: str) -> str:
|
||||||
"""
|
"""
|
||||||
https://en.wikipedia.org/wiki/ROT13
|
https://en.wikipedia.org/wiki/ROT13
|
||||||
|
|
||||||
@ -9,7 +9,8 @@ def dencrypt(s: str, n: int = 13) -> str:
|
|||||||
>>> dencrypt(s) == msg
|
>>> dencrypt(s) == msg
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
out = ""
|
out = []
|
||||||
|
n=13
|
||||||
for c in s:
|
for c in s:
|
||||||
if "A" <= c <= "Z":
|
if "A" <= c <= "Z":
|
||||||
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
|
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
|
||||||
@ -17,16 +18,16 @@ def dencrypt(s: str, n: int = 13) -> str:
|
|||||||
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
|
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
|
||||||
else:
|
else:
|
||||||
out += c
|
out += c
|
||||||
return out
|
return ''.join(out)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
s0 = input("Enter message: ")
|
s0 = input("Enter message: ")
|
||||||
|
|
||||||
s1 = dencrypt(s0, 13)
|
s1 = dencrypt(s0)
|
||||||
print("Encryption:", s1)
|
print("Encryption:", s1)
|
||||||
|
|
||||||
s2 = dencrypt(s1, 13)
|
s2 = dencrypt(s1)
|
||||||
print("Decryption: ", s2)
|
print("Decryption: ", s2)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user