 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements
 