jukaukor

enigmaencrypt.py

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