The Atbash cipher is a simple cipher that uses opposite values in the alphabet to transform words. For example, A is equal to Z and C is equal to X.
Since the Atbash cipher works by using the opposite value of a character in the alphabet, we can create a maketrans
feature to substitute characters:
import string input = raw_input("Please enter the value you would like to Atbash Cipher: ") transform = string.maketrans( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba") final = string.translate(input, transform) print final
After importing the correct module, we request the input from the user for the value they would like encipher into the Atbash cipher:
import string input = raw_input("Please enter the value you would like to Atbash Ciper: ")
Next, we create the maketrans
feature to be used. We do this by listing the first set of characters that we would like to be substituted and then listing another set of characters that we will use to replace the previous ones:
transform = string.maketrans( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba")
Finally, we just need to give a value to the transformation, apply it, and print the value out to get the end result:
final = string.translate(input, transform) print final
Here is an example of the script in action:
Please enter the value you would like to Atbash Cipher: testing gvhgrmt