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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.12-bookworm",
"VARIANT": "3.12-bookworm"
}
},

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ venv.bak/
.try
.vscode/
.vs/
.devcontainer/devcontainer.json
33 changes: 25 additions & 8 deletions ciphers/rot13.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
def dencrypt(s: str, n: int = 13) -> str:
def dencrypt(s: str) -> str:
"""
Applies the ROT13 cipher to the input string, `s`, shifting each alphabetic character
by 13 positions within the alphabet. This cipher is symmetrical, meaning applying it
twice returns the original text. Non-alphabet characters are left unchanged.

https://en.wikipedia.org/wiki/ROT13

Args:
s (str): The input string to be encoded/decoded using ROT13.

Returns:
str: The encoded/decoded string after applying the ROT13 transformation.

Raises:
TypeError: If the input `s` is not a string.

>>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!"
>>> s = dencrypt(msg)
>>> s
"Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!"
>>> dencrypt(s) == msg
True

"""
out = ""
if not isinstance(s, str):
raise TypeError("Input must be a string.")

out = []
for c in s:
if "A" <= c <= "Z":
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
out.append(chr(ord("A") + (ord(c) - ord("A") + 13) % 26))
elif "a" <= c <= "z":
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
out.append(chr(ord("a") + (ord(c) - ord("a") + 13) % 26))
else:
out += c
return out
out.append(c)
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
18 changes: 18 additions & 0 deletions strings/indian_phone_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,22 @@ def indian_phone_validator(phone: str) -> bool:


if __name__ == "__main__":
"""
Main entry point of the script.

This block checks if the script is being run as the main module. If so, it calls
the `indian_phone_validator` function with a sample phone number and
prints the result.

Functions:
indian_phone_validator(phone: str) -> bool:
Validates if the given phone number is a valid Indian phone number.
The function is expected to return `True` if the number is valid,
otherwise `False`.

Example:
$ python indian_phone_validator.py
True # (if the phone number "+918827897895" is valid)
Note: Ensure that the `indian_phone_validator()` function is defined.
"""
print(indian_phone_validator("+918827897895"))