Exemple #1
0
def handle_des(client_socket):
    print "[*] The connection is encrypted with DES"
    # waiting for key
    print "[*] Waiting for key..."
    try:
        key_text = client_socket.recv(1024)
        client_socket.send("Key received!")
    except:
        client_socket.close()
        print "[*] Remote client is closed."
        return

    print "[*] Key accepted. Waiting for messages..."

    while True:
        try:
            cipher_text = client_socket.recv(1024)

            if cipher_text:
                print "[*] Received: %s" % cipher_text
                print "[*] Plain text is: %s" % DES.decrypt(cipher_text, key_text)

            client_socket.send("ACK!")
        except:
            client_socket.close()
            print "[*] Remote client is closed."
            return
# Author: soachishti ([email protected])
# Link: http://page.math.tu-berlin.de/~kant/teaching/hess/krypto-ws2006/des.htm

from des import DES

d = DES()

print "\n" + "=" * 5 + "HEX Demo" + "=" * 5 + "\n"

hex_message = "0123456789abcdef"
key = "133457799BBCDFF1"  # Must be hex
encryted = d.encrypt(hex_message, key)
decrypted = d.decrypt(encryted, key)

print "Message: ", hex_message
print "Key: ", key
print "Encryted: ", encryted
print "Decrypted: ", decrypted

print "\n" + "=" * 5 + "ASCII Demo" + "=" * 5 + "\n"

ascii_message = "OwaisAli"
hex_message = d.process_message(ascii_message)
encryted = d.encrypt(hex_message, key)
decrypted = d.decrypt(encryted, key)

print "ASCII Message: ", ascii_message
print "Hex Message: ", hex_message
print "Key: ", key
print "Encryted: ", encryted
print "Decrypted: ", decrypted.decode('hex').split('\0')[0]
from des import DES

while True:
    mode = input('Select DES mode (E: Encryption, D: Decryption)\nor Enter Q to quit\nSelection: ')
    if mode == 'Q' or mode == 'q':
        break

    elif mode == 'E' or mode == 'e':
        key = input('Enter the key in hex: ')
        plain = input('Enter the plain text in hex: ')
        des = DES(key=key, plain=plain)
        print('Cipher text: ' + des.encrypt())

    elif mode == 'D' or mode == 'd':
        key = input('Enter the key in hex: ')
        cipher = input('Enter the cipher text in hex: ')
        des = DES(key=key, cipher=cipher)
        print('Plain text: ' + des.decrypt())

    print()
Exemple #4
0
 def decrypt(self):
     key = self.textEdit_2.toPlainText()
     encrypt_text = self.textEdit_3.toPlainText()
     encrypt_text_ = base64.b64decode(encrypt_text.encode('utf-8'))
     des = DES()
     decrypt_text = des.decrypt(key, encrypt_text_)
from des import DES


d = DES('qwertyui')

cipher = d.encrypt('hello world!')

print(cipher)

deciphered = d.decrypt(cipher, msg_in_bits=True)

print(deciphered)
Exemple #6
0
def main(f_input="input.txt"):
    cipher = DES()
    #cipher.encrypt("abcdefgh")
    c = cipher.encrypt(f_input)
    p = cipher.decrypt(c)
Exemple #7
0
def handle_mix(client_socket):
    # waiting for public key of the client
    print "Wating for public key of the client"
    try:
        pub_key_string_client = client_socket.recv(2048)
        pub_key_array_client = pub_key_string_client.split(',')
        pub_key_client = (long(pub_key_array_client[0]), long(pub_key_array_client[1]))
    except:
        client_socket.close()
        print "\n[*] Connection is broke."
        return

    print "[*] Client public key accepted."
    print pub_key_client

    prime_length = 512
    rsaKeys = rsa.RSAKey()
    pub_key_server, priv_key_server = rsaKeys.gen_keys(prime_length)

    # send public key
    print "[*] Keys generated. Sending public key to the client..."
    pub_key_string_server = str(pub_key_server[0]) + "," + str(pub_key_server[1])
    print pub_key_string_server
    try:
        client_socket.send(pub_key_string_server)
    except:
        client_socket.close()
        print "\n[*] Connection is broke."
        return

    # waiting for des key
    print "[*] Waiting for des key..."
    cipher_des_key =  client_socket.recv(4096)
    des_key = rsaKeys.decrypt(priv_key_server, cipher_des_key.split())
    client_socket.send("Key received!")

    # waiting for messages...
    print "[*] Key accepted. Waiting for messages..."
    while True:
        try:
            cipher_digest = client_socket.recv(102400)
            print cipher_digest

            if cipher_digest:
                print "[*] Received cipher digest: %s" % cipher_digest
                plain_digest = rsaKeys.decrypt(pub_key_client, cipher_digest.split())
                print "[*] Plain digest is: %s" % plain_digest
            client_socket.send("Digest Received!")
            cipher_text = client_socket.recv(2048)
            client_socket.send("Message Received!")
            if cipher_text:
                print "[*] Received cipher text: \n%s" % cipher_text
                plain_text = DES.decrypt(cipher_text, des_key)
                print "[*] Plain text is: \n %s" % DES.decrypt(cipher_text, des_key)
                sha1_degist = sha1.sha1(plain_text)
                print "[*] Real digest: [%s]" % sha1_degist
                if sha1_degist == plain_digest:
                    print "[*] The message is from correct client."
                else:
                    print"[*] The message was tampered."
        except:
            client_socket.close()
            print "\n[*] Connection is broke."
            return