+1 (315) 557-6473 

Python Program to Create Xor Encryption Assignment Solution.


Instructions

Objective
Write a python homework program to create xor encryption.

Requirements and Specifications

XOR Encryption in Python
What You Need
Your Kali VM, that should have Python 3 installed. And ability to read the following guideline of XOR operation.
Purpose
In this Project you will build a tool using python to encrypt and decrypt a text message using XOR method.
  • User will input a Word and to encrypt
  • User will input a Key
  • Your program will take these inputs and use the Python ord function to encrypt the word
  • Your output needs to have the following
  • Your encrypted text
  • Your plain text
  • Binary value of the plain text
  • Binary value of the Key
  • Binary value of the XOR (encrypted) output
  • Hex value of the text plain text
  • Hex value of the text encrypted text
XOR Encryption in Python
What You Need
Your Kali VM, that should have Python 3 installed. And ability to read the following guideline of XOR operation.
Purpose
In this Project you will build a tool using python to encrypt and decrypt a text message using XOR method.
  • User will input a Word and to encrypt
  • User will input a Key
  • Your program will take these inputs and use the Python ord function to encrypt the word
  • Your output needs to have the following
  • Your encrypted text
  • Your plain text
  • Binary value of the plain text Binary val
  • ue of the Key
  • Binary value of the XOR (encrypted) output
  • Hex value of the text plain text
  • Hex value of the text encrypted text

Source Code

if __name__ == '__main__':

    # Ask for string to encrypt

    input_str = input("Enter the cipher text or plain text: ")

    # Ask for key

    key = input('Enter the key for encryption or decryption: ')

    encrypt_str = ""

    decrypt_str = ""

    # Create a list to store all the encrypted values but in binary format

    encrypted_binary = list()

    # Create a list to store the decrypted values in binary

    decrypted_binary = list()

    # Create a list to store the binary of the key

    key_binary = [bin(ord(char)) for char in key]

    # Now, we XOR each character in the message with each character in the key

    key_index = 0

    # Loop through each char in message

    for char in input_str:

        key_val = ord(key[key_index]) # Get the current char in the key, converted to ord

        # Apply XOR

        xor_result = ord(char)^key_val

        # Now, we convert to char again and add to the encrypt_str variable

        encrypt_str += chr(xor_result)

        # We convert this value to binary and add to a list

        encrypted_binary.append(bin(xor_result))

        # Increment the index so in the next loop we use the next char of the key

        key_index += 1

        if key_index >= len(key): # If we reach the end of the key, we start with the first chara again

            key_index = 0

    # Now, in the next loop, we will decrypt the message

    # Loop through each char in the Encrypted Message

    for char in encrypt_str:

        key_val = ord(key[key_index]) # Get the current char in the key, converted to ord

        # Apply XOR

        xor_result = ord(char) ^ key_val

        # Now, we convert to char again and add to the encrypt_str variable

        decrypt_str += chr(xor_result)

        # We convert this value to binary and add to a list

        decrypted_binary.append(bin(xor_result))

        # Increment the index so in the next loop we use the next char of the key

        key_index += 1

        if key_index >= len(key): # If we reach the end of the key, we start with the first chara again

            key_index = 0

    # Finally, we print the results

    print("Here's the encrypted output:", encrypt_str)

    print("Here's the decrypted output:", decrypt_str)

    print("Here's the binary of the encrypted output:", *encrypted_binary)

    print("Here's the binary of the key:", *key_binary)

    print("Here's the binary of the decrypted output:", *decrypted_binary)