jukaukor

Enigma_encrypt.py

Nov 2nd, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1.  
  2. from enigma.machine import EnigmaMachine
  3.  
  4. # setup machine according to specs from a daily key sheet:
  5.  
  6. machine = EnigmaMachine.from_key_sheet(
  7. rotors='II IV V',
  8. reflector='B',
  9. ring_settings='B U L',
  10. plugboard_settings='AV BS CG DL FU HZ IN KM OW RX')
  11.  
  12. rotorpositions = input("Anna roottorin alkuasetukset, 3 isoa kirjainta, esim WXC ")
  13. print("initial rotor positions =",rotorpositions)
  14. # set initial rotor position
  15. machine.set_display(rotorpositions)
  16. msg_key = input("Anna message key, 3 isoa kirjainta, esim KCH")
  17. # encrypt message key
  18. enc_key = machine.process_text(msg_key) # encrypt message key
  19. print("encrypted message key = ",enc_key)
  20. machine.set_display(msg_key) # use message key
  21. plaintext = input("Anna selväkielinen teksti, isot kirjaimet ")
  22. ciphertext = machine.process_text(plaintext)
  23. print("ciphertext = ",ciphertext)
  24. print("ciphertext in five letter groups:")
  25. for i in range(0,len(ciphertext)-4):
  26. print(ciphertext[5*i:5*i+5],end=" ")
Advertisement
Add Comment
Please, Sign In to add comment