Cifras hebraicas (Atbash, Atbah e Albam) em Python


SUBMITTED BY: Guest

DATE: Oct. 3, 2013, 3:21 p.m.

FORMAT: Python

SIZE: 895 Bytes

HITS: 2271

  1. class HebrewCipher:
  2. atbash = 'ZYXWVUTSRQPONMLKJIHGFEDCBA'
  3. albam = 'NOPQRSTUVWXYZABCDEFGHIJKLM'
  4. atbah = 'IHGFNDCBARQPOEMLKJZYXWVUTS'
  5. def __init__(self):
  6. self.__plain = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  7. def encrypt(self, text, cipher):
  8. ''' (HebrewCipher, str, str) -> str
  9. Retorna o texto cifrado com
  10. a cifra hebraica escolhida
  11. '''
  12. txt = ''
  13. text = text.replace(' ', '').upper()
  14. for ch in text:
  15. idx = self.__plain.find(ch)
  16. txt += cipher[idx]
  17. return txt
  18. def decrypt(self, text, cipher):
  19. ''' (HebrewCipher, str, str) -> str
  20. Retorna o texto decifrado com
  21. a cifra hebraica escolhida
  22. '''
  23. return self.encrypt(text, cipher).lower()

comments powered by Disqus