O(n) Rotational Cipher in Python

The Cloud is the future: Get Certified now.

Rotational Cipher: One simple way to encrypt a string is to “rotate” every alphanumeric character by a certain amount. Rotating a character means replacing it with another character that is a certain number of steps away in normal alphabetic or numerical order. For example, if the string “Zebra-493?” is rotated 3 places, the resulting string is “Cheud-726?”. Every alphabetic character is replaced with the character 3 letters higher (wrapping around from Z to A), and every numeric character replaced with the character 3 digits higher (wrapping around from 9 to 0). Note that the non-alphanumeric characters remain unchanged. Given a string and a rotation factor, return an encrypted string.

Signature

string rotationalCipher(string input, int rotationFactor)

Input

1 <= |input| <= 1,000,000 0 <= rotationFactor <= 1,000,000

Output

Return the result of rotating input a number of times equal to rotationFactor.

Example 1

input = Zebra-493?

‎AWS Cloud Practitioner PRO
‎AWS Cloud Practitioner PRO
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot

rotationFactor = 3

output = Cheud-726?

Example 2

input = abcdefghijklmNOPQRSTUVWXYZ0123456789

rotationFactor = 39

output = nopqrstuvwxyzABCDEFGHIJKLM9012345678

O(n) Solution in Python:

‎AWS Cloud Practitioner PRO
‎AWS Cloud Practitioner PRO
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot
  • ‎AWS Cloud Practitioner PRO Screenshot

Test 1:

PS C:\dev\scripts> .\test_rotational_cipher_python.py
Length Dic Numbers : 10
Length Dic lowercase : 26
Length Dic uppercase : 26
Input: Zebra-493?
Output: Cheud-726?

Test2:

PS C:\dev\scripts> .\test_rotational_cipher_python.py
Length Dic Numbers : 10
Length Dic lowercase : 26
Length Dic uppercase : 26
Input: abcdefghijklmNOPQRSTUVWXYZ0123456789
Output: nopqrstuvwxyzABCDEFGHIJKLM9012345678

The Cloud is the future: The AWS Certified Solutions Architect – Associate Average salary is $149,446/year. Get Certified Now with the apps below:



Solution Architect PRO
Solution Architect PRO
Developer:
‪Etienne Noumen‬
Price:
$5.39

  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot
  • Solution Architect PRO Screenshot




AWS Certified Cloud Practitioner Mock Exams Pro
AWS Certified Cloud Practitioner Mock Exams Pro
Developer:
‪Etienne Noumen‬
Price:
$5.39

  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot
  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot
  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot
  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot
  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot
  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot
  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot
  • AWS Certified Cloud Practitioner Mock Exams Pro Screenshot





AWS Certified Developer Associate Exam Prep
AWS Certified Developer Associate Exam Prep
Developer:
‪Etienne Noumen‬
Price:
Free

  • AWS Certified Developer Associate Exam Prep Screenshot
  • AWS Certified Developer Associate Exam Prep Screenshot
  • AWS Certified Developer Associate Exam Prep Screenshot
  • AWS Certified Developer Associate Exam Prep Screenshot
  • AWS Certified Developer Associate Exam Prep Screenshot
  • AWS Certified Developer Associate Exam Prep Screenshot
  • AWS Certified Developer Associate Exam Prep Screenshot
  • AWS Certified Developer Associate Exam Prep Screenshot


Djamga PRO: Pick Up Games, Health and Fitness Calculator
Djamga PRO: Pick Up Games, Health and Fitness Calculator
Developer:
‪Etienne Noumen‬
Price:
$3.49

  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot
  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot
  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot
  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot
  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot
  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot
  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot
  • Djamga PRO: Pick Up Games, Health and Fitness Calculator Screenshot


Get 20% off Google Workspace (including Google Meet) Business Plan (Americas): L9H4RENHLPH76FV
Get 20% off Google Google Workspace (including Google Meet) Standard Plan with the following codes: 96DRHDRA9J7GTN6
Contact us for more codes

taimienphi.vn