def decrypt_string(self, s): """Decrypt given string, using current user password""" s=base64.decodestring(s) # s was base64ed l=len(s) s2=[] for i in range(0,l/16): x=s[i*16:(i+1)*16] x=rijndael.decrypt(self._mdkey,x) s2.append(x) # uncipher us=string.join(s2,'') # rejoin all us=us.rstrip() return us
def decrypt_cbc(s, iv, key): p = b"".join( rijndael.decrypt(key, bytes(s[i:i + len(iv)])) for i in range(0, len(s), len(iv))) return bytes((iv + s)[i] ^ p[i] for i in range(len(p)))
def _decrypt(self, s, key): """Returns the s string decrypted with key""" mdkey=md5.md5(key).hexdigest() s=base64.decodestring(s) return rijndael.decrypt(mdkey,s)
def decrypt_cbc(s, iv, key): p = "".join( rijndael.decrypt(key, "".join(s[i:i + len(iv)])) for i in xrange(0, len(s), len(iv))) return "".join(chr(ord((iv + s)[i]) ^ ord(p[i])) for i in xrange(len(p)))
def clickedBtn(self): if self.radioButton.isChecked(): way = '1' else: way = '2' input_path = self.lineEdit.text() if os.path.isfile(input_path): pass else: self.textEdit.setPlainText("This is not a file! Check a path!\n") return key = self.lineEdit2.text() time_before = time.time() # Input data with open(input_path, 'rb') as f: data = f.read() if way == '1': crypted_data = [] temp = [] for byte in data: temp.append(byte) if len(temp) == 16: print("123") crypted_part = rijndael.encrypt(temp, key) crypted_data.extend(crypted_part) del temp[:] else: #padding v1 # crypted_data.extend(temp) # padding v2 if 0 < len(temp) < 16: empty_spaces = 16 - len(temp) for i in range(empty_spaces - 1): temp.append(0) temp.append(1) crypted_part = rijndael.encrypt(temp, key) crypted_data.extend(crypted_part) out_path = os.path.join(os.path.dirname(input_path), 'crypted_' + os.path.basename(input_path)) if os.path.exists(out_path): os.remove(out_path) # Ounput data with open(out_path, 'xb') as ff: ff.write(bytes(crypted_data)) self.textEdit.setPlainText( "Encryption is successful! Check the file with name crypted_" + os.path.basename(input_path) + "\n") else: # if way == '2' decrypted_data = [] temp = [] for byte in data: temp.append(byte) if len(temp) == 16: decrypted_part = rijndael.decrypt(temp, key) decrypted_data.extend(decrypted_part) del temp[:] else: #padding v1 # decrypted_data.extend(temp) # padding v2 if 0 < len(temp) < 16: empty_spaces = 16 - len(temp) for i in range(empty_spaces - 1): temp.append(0) temp.append(1) decrypted_part = rijndael.encrypt(temp, key) decrypted_data.extend(crypted_part) out_path = os.path.join( os.path.dirname(input_path), 'decrypted_' + os.path.basename(input_path)) if os.path.exists(out_path): os.remove(out_path) # Ounput data with open(out_path, 'xb') as ff: ff.write(bytes(decrypted_data)) self.textEdit.setPlainText( "Decryption is successful! Check the file with name decrypted_" + os.path.basename(input_path) + "\n") time_after = time.time() return
def decrypt_cbc(s, iv, key): p = b"".join(rijndael.decrypt(key, bytes(s[i:i+len(iv)])) for i in range(0, len(s), len(iv))) return bytes((iv+s)[i] ^ p[i] for i in range(len(p)))