Skip to content

Instantly share code, notes, and snippets.

@MawCeron
Last active March 27, 2019 23:07
Show Gist options
  • Select an option

  • Save MawCeron/cda8b9d6281722c040488cd447fdf5d4 to your computer and use it in GitHub Desktop.

Select an option

Save MawCeron/cda8b9d6281722c040488cd447fdf5d4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Encrypts and decrypts messages using the Atbash cipher
#
#
# (c) 2014 Mauricio Cerón <maw.ceron@gmail.com>
#
def atbash(message):
alphabet = u'A B C D E F G H I J K L M N Ñ O P Q R S T U V W X Y Z a b c d e f g h i j k l m n ñ o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9'.split()
backward = u'Z Y X W V U T S R Q P O Ñ N M L K J I H G F E D C B A z y x w v u t s r q p o ñ n m l k j i h g f e d c b a 9 8 7 6 5 4 3 2 1 0'.split()
cipher = []
for letter in message:
if letter in alphabet:
for i in xrange(len(alphabet)):
if alphabet == letter:
pos = i
cipher.append(backward[pos])
else:
cipher.append(letter)
new_message = ''.join(cipher)
return new_message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment