SHARE
TWEET

Untitled

a guest Feb 21st, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def enigma(text, ref, rot1, shift1, rot2, shift2, rot3, shift3):
  2.     text = text.upper()
  3.     rotor0 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  4.     if rot1 == 1:
  5.         rotor1 = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"
  6.     if rot2 == 2:
  7.         rotor2 = "AJDKSIRUXBLHWTMCQGZNPYFVOE"
  8.     if rot3 == 3:
  9.         rotor3 = "BDFHJLCPRTXVZNYEIWGAKMUSQO"
  10.     if ref == 1:
  11.         reflectorB = {"A":"Y", "Y":"A","B":"R","R":"B","C":"U","U":"C","D":"H","H":"D","E":"Q","Q":"E","F":"S","S":"F","G":"L","L":"G","I":"P","P":"I","J":"X","X":"J","K":"N","N":"K","M":"O","O":"M","T":"Z","Z":"T","V":"W","W":"V" }
  12.     res_text = ""
  13.     result = ""
  14.     for i in text:
  15.         if i in rotor0:
  16.             res_text += i
  17.     for i in res_text:
  18.         ind = rotor0.index(i)
  19.         ind = ind+shift3
  20.         while (ind>len(rotor0)) or (ind<len(rotor0)-1):
  21.             if ind>len(rotor0)-1:
  22.                 ind = ind-len(rotor0)
  23.             if ind<0:
  24.                 ind = ind+len(rotor0)
  25.         symbol = ""
  26.         if rot3 == 3:
  27.             symbol = rotor3[ind+(shift2-shift3)]
  28.         if rot2 == 2:
  29.             if rot3 == 3:
  30.                 ind = rotor0.index(symbol)+(-shift2+shift1)
  31.                 symbol = rotor2[ind]
  32.             else:
  33.                 symbol = rotor2[ind]
  34.         if rot1 == 1:
  35.             if rot2 == 2:
  36.                 ind = rotor0.index(symbol)-shift1
  37.                 symbol = rotor1[ind]
  38.             else:
  39.                 symbol = rotor1[ind]
  40.         if ref == 1:
  41.             symbol = reflectorB[symbol]
  42.         ind = rotor1.index(symbol)+shift1
  43.         symbol = rotor0[ind]
  44.         if rot2 == 2:
  45.             ind = rotor2.index(symbol)+(shift2-shift1)
  46.             symbol = rotor0[ind]
  47.         if rot3 == 3:
  48.             ind = rotor3.index(symbol)-shift3
  49.             symbol = rotor0[ind]
  50.         result += symbol
  51.     return result
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top