maxunderwood4


SUBMITTED BY: schnebi

DATE: March 30, 2016, 10:45 a.m.

FORMAT: Text only

SIZE: 1.0 kB

HITS: 1061

  1. class Polybius:
  2. 2. def __init__(self):
  3. 3. ## p_alphabet nao possui a letra j, que sera substituida
  4. 4. ## pela letra i na cifragem e decifragem
  5. 5. self.p_alphabet = 'abcdefghiklmnopqrstuvwxyz'
  6. 6. self.p_alphanum = 'abcdefghijklmnopqrstuvwxyz0123456789'
  7. 7.
  8. 8. def cipher_alphabet(self, password):
  9. 9. ''' (str) -> str
  10. 10. Retorna um alfabeto cifrado iniciado com
  11. 11. o texto da palavra chave password
  12. 12. '''
  13. 13. c_alphabet = []
  14. 14. p_alphabet = self.p_alphanum
  15. 15. for ch in password:
  16. 16. if ch not in c_alphabet:
  17. 17. c_alphabet.append(ch)
  18. 18. idx = p_alphabet.find(ch)
  19. 19. p_alphabet = p_alphabet[idx:] + p_alphabet[:idx]
  20. 20. for ch in p_alphabet:
  21. 21. if ch not in c_alphabet:
  22. 22. c_alphabet.append(ch)
  23. 23. return ''.join(c_alphabet)

comments powered by Disqus