0% found this document useful (0 votes)
6 views

Pyhtin 2

Uploaded by

mana khant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Pyhtin 2

Uploaded by

mana khant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

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

1. Aim: String Rotator for Cryptography Tool :


A cryptography tool needs a function to rotate text as part
of its encryption process. Implement a function rotate
string (s: str, n: int) -> str that takes a string and rotates it
by n characters to the right (or left if n is negative). This
function will be used to create simple ciphers and
introduce beginners to the concept of text transformation
in cryptography.

2. Requirements (Hardware/Software): Any modern


processor (e.g., Intel Core i3), at least 2 GB of RAM,
minimal storage space. Software: Operating System:
Windows, macOS, or Linux. Python: Python 3.x (latest
version recommended).

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

# Normalize n to be within the length of the string


n %= len(s)

# Perform the rotation


rotated = s[-n:] + s[:-n]
return rotated

# 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

You might also like