daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def setupUi(self, Encryptor):
  2.     Encryptor.setObjectName("Encryptor")
  3.     Encryptor.setEnabled(True)
  4.     Encryptor.resize(401, 312)
  5.     Encryptor.setWindowOpacity(1.0)
  6.     Encryptor.setTabShape(QtWidgets.QTabWidget.Rounded)
  7.     self.centralwidget = QtWidgets.QWidget(Encryptor)
  8.     self.centralwidget.setObjectName("centralwidget")
  9.     self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
  10.     self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 90, 381, 31))
  11.     self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
  12.     self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
  13.     self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
  14.     self.horizontalLayout.setObjectName("horizontalLayout")
  15.     self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
  16.     self.lineEdit.setObjectName("lineEdit")
  17.     self.horizontalLayout.addWidget(self.lineEdit)
  18.     self.label = QtWidgets.QLabel(self.centralwidget)
  19.     self.label.setGeometry(QtCore.QRect(10, 10, 379, 69))
  20.     self.label.setObjectName("label")
  21.     self.pushButton = QtWidgets.QPushButton(self.centralwidget)
  22.     self.pushButton.setGeometry(QtCore.QRect(10, 130, 181, 71))
  23.     self.pushButton.setObjectName("pushButton")
  24.     self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
  25.     self.pushButton_2.setGeometry(QtCore.QRect(200, 130, 191, 71))
  26.     self.pushButton_2.setObjectName("pushButton_2")
  27.     Encryptor.setCentralWidget(self.centralwidget)
  28.     self.statusbar = QtWidgets.QStatusBar(Encryptor)
  29.     self.statusbar.setObjectName("statusbar")
  30.     Encryptor.setStatusBar(self.statusbar)
  31.     self.retranslateUi(Encryptor)
  32.     QtCore.QMetaObject.connectSlotsByName(Encryptor)
  33.     self.pushButton.clicked.connect(self.OpenClick)
  34.     self.pushButton_2.clicked.connect(self.OpenClick2)
  35.  
  36. def retranslateUi(self, Encryptor):
  37.     _translate = QtCore.QCoreApplication.translate
  38.     Encryptor.setWindowTitle(_translate("Encryptor", "Encryptor"))
  39.     self.label.setText(_translate("Encryptor", "92048208493598953532080Enter the file Directory029402909310324020490"))
  40.     self.pushButton.setText(_translate("Encryptor", "Encrypt"))
  41.     self.pushButton_2.setText(_translate("Encryptor", "Decrypt"))
  42.  
  43. def LineInput(self):
  44.     self.lineEdit.text()
  45.  
  46. def OpenClick(self):
  47.     Encryptors.incript()
  48.  
  49. def OpenClick2(self):
  50.     Encryptors.dicript()
  51.    
  52. def pad(self, s):
  53.     return s + b"" * (AES.block_size - len(s) % AES.block_size)
  54.  
  55. def encrypt(self, message, key, key_size=256):
  56.     message = self.pad(message)
  57.     iv = Random.new().read(AES.block_size)
  58.     cipher = AES.new(key, AES.MODE_CBC, iv)
  59.     return iv + cipher.encrypt(message)
  60.  
  61. def encrypt_file(self, file_name):
  62.     with open(file_name, 'rb')as fo:
  63.         plaintext = fo.read()
  64.     enc = self.encrypt(plaintext, self.key)
  65.     with open(file_name + ".enc", 'wb') as fo:
  66.         fo.write(enc)
  67.         os.remove(file_name)
  68.  
  69. def decrypt(self, ciphertext, key):
  70.     iv = ciphertext[:AES.block_size]
  71.     cipher = AES.new(key, AES.MODE_CBC, iv)
  72.     plaintext = cipher.decrypt(ciphertext[AES.block_size:])
  73.     return plaintext.rstrip(b"")
  74.  
  75. def decrypt_file(self, file_name):
  76.     with open(file_name, 'rb') as fo:
  77.         ciphertext = fo.read()
  78.     dec = self.decrypt(ciphertext, self.key)
  79.     with open(file_name[:-4], 'wb') as fo:
  80.         fo.write(dec)
  81.     os.remove(file_name)
  82.  
  83. def getAllFiles(self):
  84.     dir_path = os.path.dirname(os.path.realpath(__file__))
  85.     dirs = []
  86.     for dirName, subdirList, fileList in os.walk(dir_path):
  87.         for fname in fileList:
  88.             if (fname != 'script.py' and fname != 'data.txt.enc'):
  89.                 dirs.append(dirName + "\" + fname)
  90.     return dirs
  91.  
  92. def encrypt_all_files(self):
  93.     dirs = self.getAllFiles()
  94.     for file_name in dirs:
  95.         self.encrypt_file(file_name)
  96.  
  97. def decrypt_all_files(self):
  98.     dirs = self.getAllFiles()
  99.     for file_name in dirs:
  100.         self.decrypt_file(file_name)
  101.  
  102. def incript():
  103.     u = Ui_Encryptor()
  104.     enc.encrypt_file(str(u.lineEdit.text()))
  105.  
  106. def dicript():
  107.     u = Ui_Encryptor()
  108.     enc.decrypt_file(str(u.LineInput()))
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