def run(self): if (self.algorithm == 'RSA'): t = xRsa() print("Running RSA Decryption") #cipher = raw_input("Cipher text: ") plaintext = t.decrptyMsg(14638872678012233450065572822) # Print the string content after encryption and decryption print("decrypted text:" + plaintext) elif (self.algorithm == 'MD5'): print("unsupported") elif (self.algorithm == 'DES'): print("Running DES Decryption") desObj = des() desObj.decryption( "key.txt", "file(txt).des" ) # thie will generate file.txt at the same directory elif (self.algorithm == 'VG'): print("Running VG Decryption") obj = VG() cipher_text = input("Cipher_text: ") key = input("Key: ") obj.create_table(key) deciper_text = obj.decipher(cipher_text, key) print(deciper_text) else: print("end")
def decrypt(filename): k = des(b"87629ae8", CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5) with open(filename, "rb") as file: encrypted_data = file.read() decrypted_data = k.decrypt(encrypted_data) with open(filename, "wb") as file: file.write(decrypted_data)
def calculate(self): algo = des() file = 'en_des_input.txt' f = open(file, 'r+') f.truncate(0) plane_text = self.ids.plane.text f.write(plane_text) key_file = '../key.txt' algo.encryption(keyPath=key_file, filename=file) o = open('en_des_input(txt).des') self.ids.cipher.text = o.read()
def DesShow(self): plaintext = self.Input.get() or '' k = des.des(b"DESCRYPT", des.CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=des.PAD_PKCS5) d = k.encrypt(plaintext) Encrypted = str(d).replace('b', '', 1) self.DesDecrypted = str(k.decrypt(d)).replace('b', '', 1) DesCipher = Encrypted self.DesText.set(DesCipher)
def _try_decrypt_response(self, response=None): #attempt to decrypt each of the common passwords #really inefficient, but it means we don't have to rely on #a static challenge for password in COMMON_PASSWORDS: pw = password[:8]#vnc passwords are max 8 chars if len(pw) < 8: pw+= '\x00'*(8-len(pw)) #VNC use of DES requires password bits to be mirrored pw = ''.join([chr(int('{:08b}'.format(ord(x))[::-1], 2)) for x in pw]) desbox = des(pw) decrypted_challenge = desbox.decrypt(response) if decrypted_challenge == self.challenge: return password return None
def run(self): if (self.algorithm == 'RSA'): print("Running RSA Encrption") msg = raw_input('Message: ') t = xRsa() print("plain text:" + msg) cipher = t.encrptyMsg(msg) print("cipher text:" + str(cipher)) elif (self.algorithm == 'MD5'): print("Running MD5 Encrption") key = input("key:") obj = MD5_State() buff = [''] * 16 ciper = obj.md5_digest(key, len(key), buff) print("deciper_text =") for i in range(16): print("%x" % ((ord(buff[i]) & 0xF0) >> 4), end='') print("%x" % (ord(buff[i]) & 0x0F), end='') #encryption = MD5() elif (self.algorithm == 'DES'): print("Running DES Encrption") desObj = des() desObj.encryption( "key.txt", "file.txt" ) # this will generte file(des).txt at the same directory elif (self.algorithm == 'VG'): print("Running VG Encrption") key = raw_input('key:') input_string = raw_input('input_string:') obj = VG() obj.create_table(key) print('key') print(obj.dict_key) print(obj.dict_char2int) print(obj.dict_int2char) print(obj.table) ciper_text = obj.cipher(input_string, key) print(ciper_text) else: print('END')
def rm_parity(num): n = bin(num)[2:].zfill(64) c = [j for i, j in enumerate(n) if (i + 1) % 8 != 0] return int(''.join(c), 2) if len(sys.argv) != 2: print("Error, wrong arguments, format: ./program_name N_test") sys.exit(-1) N = int(sys.argv[1], 10) # Get class to performa a correct encription and setup some empty list needed for the test d = des.des() pt = [] key = [] ct_list = [] lr_correct_list = [] cd_correct_list = [] k_correct_list = [] # Define the path for the working folder path = os.getcwd() # Set compiler flags arg = '-2008' compiler = 'vcom' # Set component to simulate toplevel = 'des'
key = inputkey.read() confirm = 0 confirm1 = 0 print("\nEscolha o que deseja fazer") while confirm == 0: print("\n[1]Login\n[2]Criar um usuario\n[3]Decifrar mensagem\n[4]Sair") escolha = int(input("\nDigite sua escolha: ")) if escolha == 1: print("Você escolheu fazer login") confirm = 1 user = input("Digite seu usuário: ") textin = input("Digite sua mensagem de 8 digitos: ") d = des() r = d.encrypt(key, textin) senhah = ("( r)", r) passDB = """SELECT senha FROM aps_table WHERE login = '******' """ ( user) apscursor.execute(passDB) senhadb = apscursor.fetchone() if str(senhadb) == str(senhah): print("Login feito com sucesso!") print("Sua senha cifrada é: ", senhah) d = des() r = d.encrypt(key, textin) r2 = d.decrypt(key, r) print("Sua mensagem decifrada é: ", r2)
plain_text = raw_input('plain_text:') table = vg_1.create_table(key) print("Table created!") print(table) cipher_text = vg_1.cipher(plain_text, key) print("Encrypted finish") print(cipher_text) decrypt = raw_input("decript yes or no:") if decrypt == "yes": vg_1.decipher(cipher_text, key) decrypt_text = vg_1.decipher(cipher_text, key) print("Decrypted finished!") print(decrypt_text) continue elif type == 'des': des_1 = des() key_file = raw_input("Please input the path of key file:") string_file = raw_input( "Please input the path of the plain_text file:") des_1.encryption(key_file, string_file) options = raw_input('decrypt yes or no:') if options == "yes": des_file = raw_input("Please input the path of des file:") key_file = raw_input("Please input the path of key file:") des_1.decryption(key_file, des_file) else: continue elif type == 'md5': md5_1 = MD5_State() key = raw_input("key:") buff = [''] * 16
# -*- coding:utf-8 -*- import des data = "123ssx" k = des.des(b"DESCRYPT", des.CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=des.PAD_PKCS5) d = k.encrypt(data) print(str(d).replace('b', '', 1)) E = ("Encrypted: " + str(d).replace('b', '', 1)) D = ("Decrypted: " + str(k.decrypt(d)).replace('b', '', 1)) print(E) print(D) # assert (k.decrypt(d) == data)
# -*- coding: utf-8 -*- from des import des key = '1' message = '0123456789ABCDEF' des = des(key, message) des.encrypt()
# send des_key message = ('des_key') mySocket.sendto(message.encode(), (SERVER_IP, PORT_NUMBER)) # ##################################your code goes here##################################### # encode the DES key with RSA and save in DES_encoded, the value below is just an example des_encoded = [] for i in message: cipher = encrypt(private, i) des_encoded.append(cipher) [ mySocket.sendto(code.encode(), (SERVER_IP, PORT_NUMBER)) for code in des_encoded ] # read image, encode, send the encoded image binary file file = open(r'penguin.jpg', "rb") data = file.read() file.close() # ##################################your code goes here##################################### # the image is saved in the data parameter, you should encrypt it using des.py # set cbc to False when performing encryption, you should use the des class # use bytearray to send the encryped image through network # r_byte is the final value you will send through socket coder = des.des() newdata = coder.encrypt(des_key, data, padding=False, cbc=False) r_byte = bytearray(newdata) # send image through socket mySocket.sendto(bytes(r_byte), (SERVER_IP, PORT_NUMBER)) print('encrypted image sent!')
print( "You may have spelt the filename incorrectly, or the file doesn't exist.\nPlease try again" ) return None finally: return values if __name__ == "__main__": # IO if len(sys.argv) is 3: args = sys.argv del args[0] values = parse_file(args[0]) # takes file input (2nd argument) if len(values) is not 0: if values['T'] == '0': _des = des.des(values['K'], "encrypt") print("Encrypting using:\nPlaintext P: {}\nKey K: {}".format( values['P'], values['K'])) text, key = _des.encrypt(values['P']) print("Ciphertext C: {}".format(text)) avalanche = des.avalanche(values['P'], values['K']) print("Avalanche:\n{}".format(avalanche)) try: # file output with open(args[1], 'w') as f: f.write( "ENCRYPTION\nPlaintext P: {}\nKey K: {}\nCiphertext C: {}\nAvalanche:\n{}" .format(values['P'], key, text, avalanche)) print("The results were saved to: {}".format(args[1])) except Exception: print("An error occurred: {}".format( traceback.format_exc()))
while len(des_key) != 8: # ensure proper input length print("wrong! 8 characters. Try again:") des_key = input() # encrypt the DES key print("encrypting DES KEY with RSA") des_encoded = [str(encrypt(public, chars)) for chars in des_key] print("the encrypted key is " + str(des_encoded)) # encrypt the image with DES print('encrypting image using DES') file = open(r'penguin.jpg', "rb") image_data = file.read() file.close() coder = des.des() # des is a class defined in des.py r = coder.encrypt(des_key, image_data, cbc=False) # encrypted image # write the encrypted image into file r_byte = bytearray() for x in r: r_byte += bytes([ord(x)]) file = open(r'penguin_encrypted.bin', "wb+") file.write(r_byte) file.close() # recover DES Key des_key_decoded = [] for data in des_encoded: cipher = int(data) des_key_decoded += decrypt(private, cipher)
df_append = pd.DataFrame([np.random.randint(9, size=100)]) df_trace = pd.concat([df_prepend, df_trace, df_append], axis=1, ignore_index=True) # Print Data # print(binascii.hexlify(trace.data).decode('utf8')) # print("Plaintext " + binascii.hexlify(trace.data).decode('utf8')[0:16]) # print("Chipertext " + binascii.hexlify(trace.data).decode('utf8')[16:32]) # print("Key " + binascii.hexlify(trace.data).decode('utf8')[32:48]) data = binascii.hexlify(trace.data).decode('utf8') if ALG == DES: if args.k is None: key = bytes.fromhex(data[32:]) k = des.des(key, des.ECB) else: if len(args.k[0]) == 16: key = bytes.fromhex(args.k[0]) k = des.des(key, des.ECB) else: exit("Invalid Key Length for DES") # Compute DES intermediate values d, sbox_in, sbox_out, r_in, r_out = k.encrypt( bytes.fromhex(data[0:16])) # Pad Sbox_Out with 0 bits at front and back sbox_count = 8 front = 0 back = 5 while sbox_count > 0: