Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ciphers/rot13.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def dencrypt(s: str, n: int = 13) -> str:
def dencrypt(s: str) -> str:
"""
https://en.wikipedia.org/wiki/ROT13

Expand All @@ -9,24 +9,25 @@ def dencrypt(s: str, n: int = 13) -> str:
>>> dencrypt(s) == msg
True
"""
out = ""
n = 13
out: list[str] = []
for c in s:
if "A" <= c <= "Z":
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
elif "a" <= c <= "z":
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
else:
out += c
return out
return "".join(out)


def main() -> None:
s0 = input("Enter message: ")

s1 = dencrypt(s0, 13)
s1 = dencrypt(s0)
print("Encryption:", s1)

s2 = dencrypt(s1, 13)
s2 = dencrypt(s1)
print("Decryption: ", s2)


Expand Down
2 changes: 1 addition & 1 deletion data_structures/arrays/sudoku_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def unitsolved(unit):

def from_file(filename, sep="\n"):
"Parse a file into a list of strings, separated by sep."
return open(filename).read().strip().split(sep) # noqa: SIM115
return open(filename).read().strip().split(sep)


def random_puzzle(assignments=17):
Expand Down