diff --git a/Image_text_hider/img_text_hider.py b/Image_text_hider/img_text_hider.py new file mode 100644 index 0000000000..b998381f8d --- /dev/null +++ b/Image_text_hider/img_text_hider.py @@ -0,0 +1,60 @@ +import argparse +from stegano import lsb +import os + +def hide_text_in_image(image_path, text, output_path): + secret_image = lsb.hide(image_path, text) + secret_image.save(output_path) + +def reveal_text_from_image(image_path): + try: + secret_text = lsb.reveal(image_path) + return (secret_text,1) #here 1 and 0 are used to enhance script quality + except UnicodeDecodeError: + return ("Unable to reveal text. Decoding error occurred.",0) + except IndexError: + return("Failed to find message in this file format, Try using different file format like png",0) + except Exception as e: + return(f"Contact the owner! {e}",0) + +def main(): + print("\n[Welcome to Image text hider this script can hide text inside image]\n") + print("To Hide the text inside image\nUSAGE: python img_text_hider.py hide img_name_with_path.jpg 'This is my secret msg' output_file_name.jpg\n") + print("To reveal the hidden text inside image\nUSAGE: python img_text_hider.py reveal hidden_img_name.jpg\n") + parser = argparse.ArgumentParser(description="Image Text Hider") + + subparsers = parser.add_subparsers(dest="command", help="Available commands") + + # Hide command + hide_parser = subparsers.add_parser("hide", help="Hide text behind an image") + hide_parser.add_argument("image", help="Path to the image file") + hide_parser.add_argument("text", help="Text to hide") + hide_parser.add_argument("output", help="Output path for the image with hidden text") + + # Reveal command + reveal_parser = subparsers.add_parser("reveal", help="Reveal text from an image") + reveal_parser.add_argument("image", help="Path to the image file") + + args = parser.parse_args() + + if args.command == "hide": + if os.path.exists(args.image): + hide_text_in_image(args.image, args.text, args.output) + print("Text hidden in the image successfully. Output image saved at", args.output) + else: + print("Image path you specified does not exist, Make sure to check image path and file name with extention") + elif args.command == "reveal": + if os.path.exists(args.image): + + revealed_text,check = reveal_text_from_image(args.image) + + if check==1: #if works out well + print(f"Revealed text: [{revealed_text}]") + else: # else display with error so that user can troubleshot the problem easily + print(f'Error!,{revealed_text}') + + else: + print("Image path you specified does not exist, Make sure to check image path and file name with extention") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Image_text_hider/readme.md b/Image_text_hider/readme.md new file mode 100644 index 0000000000..6c8961c4a2 --- /dev/null +++ b/Image_text_hider/readme.md @@ -0,0 +1,30 @@ +# Image Text Hider + +This script allows you to hide text inside an image using steganography. It utilizes the LSB (Least Significant Bit) technique to embed the text into the image without visibly altering the image. + +## Requirements + +- Python 3.6 or above +- Install the required packages by running `pip install -r requirements.txt`. + +## Usage + +To hide text inside an image: +python img_text_hider.py hide + +- ``: Path to the image file. +- ``: Text to hide inside the image. +- ``: Output path for the image with hidden text. + +To reveal the hidden text from an image: +python img_text_hider.py reveal + +- ``: Path to the image file with hidden text. + +## Example + +Hide text inside an image: +python img_text_hider.py hide my_image.jpg "This is my secret message" output_image.jpg + +Reveal the hidden text from an image: +python img_text_hider.py reveal output_image.jpg \ No newline at end of file diff --git a/Image_text_hider/requirements.txt b/Image_text_hider/requirements.txt new file mode 100644 index 0000000000..190a33b2b1 --- /dev/null +++ b/Image_text_hider/requirements.txt @@ -0,0 +1,2 @@ +argparse +stegano \ No newline at end of file diff --git a/text_encryption/encryption_method.py b/text_encryption/encryption_method.py new file mode 100644 index 0000000000..0cff284dde --- /dev/null +++ b/text_encryption/encryption_method.py @@ -0,0 +1,114 @@ +import string +import sys + +# Caesar cipher encryption +def caesar_cipher_encrypt(text, shift): + encrypted_text = "" + for char in text: + if char.isalpha(): + alphabet = string.ascii_uppercase if char.isupper() else string.ascii_lowercase + encrypted_char = alphabet[(alphabet.index(char) + shift) % len(alphabet)] + encrypted_text += encrypted_char + else: + encrypted_text += char + return encrypted_text + +# Affine cipher encryption +def affine_cipher_encrypt(text, a, b): + encrypted_text = "" + for char in text: + if char.isalpha(): + alphabet = string.ascii_uppercase if char.isupper() else string.ascii_lowercase + encrypted_char = alphabet[(a * alphabet.index(char) + b) % len(alphabet)] + encrypted_text += encrypted_char + else: + encrypted_text += char + return encrypted_text + +# Substitution cipher encryption +def substitution_cipher_encrypt(text, key): + encrypted_text = "" + for char in text: + if char.isalpha(): + alphabet = string.ascii_uppercase if char.isupper() else string.ascii_lowercase + substitution_alphabet = str.maketrans(alphabet, key.upper()) if char.isupper() else str.maketrans(alphabet, key.lower()) + encrypted_char = char.translate(substitution_alphabet) + encrypted_text += encrypted_char + else: + encrypted_text += char + return encrypted_text + +# Transposition cipher encryption +def transposition_cipher_encrypt(text, key): + ciphertext = [''] * int(key) + for column in range(int(key)): + currentIndex = column + while currentIndex < len(text): + ciphertext[column] += text[currentIndex] + currentIndex += int(key) + + return ''.join(ciphertext) + +def main(): + text = input("Enter the text to encrypt: ") + + # Ask user for the encryption method + print("Choose an encryption method:") + print("1. Caesar cipher") + print("2. Affine cipher") + print("3. Substitution cipher") + print("4. Transposition cipher") + + try: + choice = int(input("Enter your choice (1-4): ")) + except ValueError: #to handle wrong values + print("Invlaid selection") + sys.exit(0) + + if choice == 1: + + try: + shift = int(input("Enter the shift value for Caesar cipher: ")) + encrypted_text = caesar_cipher_encrypt(text, shift) + print("Caesar cipher (encryption):", encrypted_text) + except ValueError: + print("Invalid Input") + + elif choice == 2: + + try: + a = int(input("Enter the value for 'a' in Affine cipher: ")) + b = int(input("Enter the value for 'b' in Affine cipher: ")) + encrypted_text = affine_cipher_encrypt(text, a, b) + print("Affine cipher (encryption):", encrypted_text) + + except ValueError: + print("Invalid Input") + + elif choice == 3: + + key = input("Enter the substitution key: ") + if len(key)==26: + encrypted_text = substitution_cipher_encrypt(text, key) + print("Substitution cipher (encryption):", encrypted_text) + else: + print("Key must have the same length as the number of characters in the alphabet (26).") + + elif choice == 4: + + try: + transpose_key = input("Enter the transposition key (make sure its less than length of stirng): ") + if int(transpose_key)>len(text): + print("Key must be less than length of string") + else: + encrypted_text = transposition_cipher_encrypt(text, transpose_key) + print("Transposition cipher (encryption):", encrypted_text) + + except ValueError: + print("Invalid Input") + + else: + print("Invalid choice. Please choose a number between 1 and 4.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/text_encryption/readme.md b/text_encryption/readme.md new file mode 100644 index 0000000000..1a5c329e85 --- /dev/null +++ b/text_encryption/readme.md @@ -0,0 +1,46 @@ +# Encryption Script + +This script allows you to encrypt text using various encryption methods. + +## Installation + +1. Make sure you have Python installed on your system. +2. Clone this repository or download the script file. + +## Usage + +1. Open a terminal or command prompt. +2. Navigate to the directory where the script is located. +3. Run the following command: python script.py + +Follow the prompts to enter the text and choose an encryption method. +Encryption Methods + +Caesar Cipher +The Caesar cipher is a substitution cipher where each letter in the plaintext is shifted a certain number of positions down the alphabet. +To choose the Caesar cipher, enter 1 when prompted. + +Affine Cipher +The Affine cipher is a substitution cipher that combines the Caesar cipher with multiplication and addition. +To choose the Affine cipher, enter 2 when prompted. + +Substitution Cipher +The Substitution cipher is a method of encryption where each letter in the plaintext is replaced by another letter according to a fixed key. +To choose the Substitution cipher, enter 3 when prompted. Note that the key must have the same length as the number of characters in the alphabet (26). + +Transposition Cipher +The Transposition cipher is a method of encryption that rearranges the letters of the plaintext to form the ciphertext. +To choose the Transposition cipher, enter 4 when prompted. You will also be asked to enter a transposition key, which should be less than the length of the text. +Note: If you enter an invalid choice or provide incorrect input, appropriate error messages will be displayed. + +Example +Here is an example of running the script: +Enter the text to encrypt: Hello, World! +Choose an encryption method: +1. Caesar cipher +2. Affine cipher +3. Substitution cipher +4. Transposition cipher +Enter your choice (1-4): 3 +Enter the substitution key: QWERTYUIOPASDFGHJKLZXCVBNM +Substitution cipher (encryption): ITSSG, KTSSG! \ No newline at end of file