Pyhtin 2
Pyhtin 2
Experiment1.2
Student 23BET10066
Name:
Gurnoor
Singh
Branch: BE-IT Section/Group BET 601(B)
Semester: 03 Date of Performance: 06 sept ,2024
Subject Name: Python Programming Subject Code:23ITP201
3. Procedure:
def rotate_string(s: str, n: int) -> str:
"""
Rotates a string by n characters to the right
(or left if n is negative).
Args:
s (str): The input string.
n (int): Number of characters to rotate
(positive for right, negative for left).
Returns:
Str: The rotated string.
"""
if not s:
return s # Return the original string
# Example usage:
original_text = "Hello, world!"
rotation_amount = 3
rotated_text=rotate_string(original_text,rotation_amount)
print(f"Original: {original_text}")
print(f"Rotated: {rotated_text}")
3. Output:
4. Learning Outcome:
Conceptual Understanding:
o Understand the purpose of string rotation in
cryptography.
o Recognize how string rotation affects the position of
characters within a text.
Algorithmic Thinking:
o Develop the ability to think algorithmically.
o Consider edge cases (e.g., empty strings, large rotation
amounts).
String Manipulation Skills:
o Learn techniques for manipulating strings (slicing,
concatenation).
o Apply string rotation logic to create a rotated version
of the input string.
Modulo Arithmetic:
o Understand the use of modulo (%) to handle cyclic
behavior (e.g., rotating beyond the string length).
Coding Practice:
o Implement the rotate_string function in Python (or
another language).
o Test the function with various inputs.
Problem Solving:
o Solve challenges related to text transformation.
o Debug and troubleshoot any issues encountered during
implementation.
Application in Cryptography:
o Recognize that string rotation is a fundamental
operation in some cryptographic algorithms.
o Appreciate how simple transformations contribute to
more complex encryption techniques