×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Python Program to Create Xor Encryption Assignment Solution

June 21, 2024
Dr. Sophia Nguyen
Dr. Sophia
🇸🇬 Singapore
Python
Dr. Sophia Nguyen holds a Doctorate in Computer Engineering from an esteemed university in Singapore and has completed over 900 assignments in Python file handling. Dr. Nguyen's expertise spans across areas such as file I/O optimizations, concurrency in file operations, and developing scalable file management systems. She excels in handling large datasets, implementing efficient error recovery strategies, and integrating file operations into web applications.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

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)

Similar Samples

At ProgrammingHomeworkHelp.com, explore our diverse portfolio of programming assignment samples. These exemplify our proficiency across multiple languages and topics, demonstrating clear, structured solutions. Whether it's algorithms, data analysis, or software development, our samples showcase our commitment to excellence in delivering top-notch programming assistance. Discover how we can help you excel in your programming coursework.