
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Atbash cipher in Python
Suppose we have a lowercase alphabet string called text. We have to find a new string where every character in text is mapped to its reverse in the alphabet. As an example, a becomes z, b becomes y and so on.
So, if the input is like "abcdefg", then the output will be "zyxwvut"
To solve this, we will follow these steps −
N := ASCII of ('z') + ASCII of ('a')
return ans by joining each character from ASCII value (N - ASCII of s) for each character s in text
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, text): N = ord('z') + ord('a') ans='' return ans.join([chr(N - ord(s)) for s in text]) ob = Solution() print(ob.solve("abcdefg")) print(ob.solve("hello"))
Input
"abcdefg" "hello"
Output
zyxwvut svool
- Related Articles
- Caesar Cipher in Python
- Difference between Block Cipher and Stream Cipher
- Difference between Monoalphabetic Cipher and Polyalphabetic Cipher
- Program to encrypt a string using Vertical Cipher in Python
- Program to encrypt a string using Vigenere cipher in Python
- XOR Cipher in C++
- Caesar Cipher in Cryptography
- Bifid Cipher in Cryptography
- Difference between Substitution Cipher Technique and Transposition Cipher Technique
- What is the comparison between Stream Cipher and Block Cipher in information security?
- Polybius Square Cipher in C++
- The Symmetric Cipher Model
- What is Block Cipher in information security?
- What is Stream Cipher in Information Security?
- What is Monoalphabetic Cipher in Information Security?

Advertisements