-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatbash.py
More file actions
executable file
·34 lines (23 loc) · 868 Bytes
/
atbash.py
File metadata and controls
executable file
·34 lines (23 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
The Atbash cipher is a particular type of monoalphabetic cipher formed by taking the
alphabet (or abjad, syllabary, etc.) and mapping it to its reverse, so that the first
letter becomes the last letter, the second letter becomes the second to last letter, and so on
'a' -> 'z' , 'b' -> 'y' etc
"""
import string
cipher_type = 'text'
cipher_alphabet = string.printable
key_length = 1
def encrypt_letter(letter):
if letter.islower():
return string.ascii_lowercase[-(1 + string.ascii_lowercase.index(letter))]
elif letter.isupper():
return string.ascii_uppercase[-(1 + string.ascii_uppercase.index(letter))]
return letter
def encrypt(plaintext, key=''):
return ''.join(list(map(encrypt_letter, plaintext)))
decrypt = encrypt
def crack(plaintext):
return encrypt(plaintext), ''