Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
<a href="https://api.github.com/repos/py-contributors/awesomescripts/contributors"><img src="https://img.shields.io/github/contributors/py-contributors/awesomeScripts?style=for-the-badge" alt="total contributors"></a>
</p>



## How to Contribute 🤔

<img align="left" alt="Coding" width="400" src="https://media.giphy.com/media/Y4ak9Ki2GZCbJxAnJD/giphy.gif">
Expand Down Expand Up @@ -58,6 +56,7 @@ before making a Pull Request
- Help us to improve script. Report a bug [here](https://github.com/Py-Contributors/awesomeScripts/issues/new?assignees=codePerfectPlus&labels=bug&template=bug_report.md&title=)

## 🤝 Scripts and contributorss 🤝

<!--Restrictions -->
<!--Don't make change under this line -->
<!-- Please don't change this, It' making conflict with upstream branch-->
Expand Down Expand Up @@ -361,6 +360,11 @@ before making a Pull Request
<td align="center">shubham5351</td>
<td align="left">Hangman is a classic word game in which you must guess words and you have given 7 chance for it.</td>
</tr>
<tr>
<td align="left"><a href="/simple-image-encryptor/script.py">simple-image-encryptor</td>
<td align="center">mohzulfikar</td>
<td align="left">Simply encrypt your image using xor operation</td>
</tr>
</tbody>
</table>

Expand Down
16 changes: 16 additions & 0 deletions simple-image-encryptor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Simple XOR Image encryptor

## Features

0. encrypt and decrypt image with xor bitwise operation
1. 2 modes of operation, enc and dec

## Usage

You can run it by typing

```
python script.py
```

After that, you can enter path to your image you want to encrypt/decrypt, and then select mode of operation.
Binary file added simple-image-encryptor/example/key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simple-image-encryptor/example/message_enc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simple-image-encryptor/example/plainpict.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions simple-image-encryptor/generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python
# python 3.8.5

import numpy
from PIL import Image


def genImage(img_width=512, img_height=256):
# Define img width and height as an integer
img_width = int(img_width)
img_height = int(img_height)

# Define key name
filename = 'key.png'
img_array = numpy.random.rand(img_height, img_width, 3) * 255
'''
Make image object from array, if u want to get
grayscale key, use "L" on convert method.
'''
image = Image.fromarray(img_array.astype('uint8')).convert('RGB')

# Save image
image.save(filename)
3 changes: 3 additions & 0 deletions simple-image-encryptor/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
opencv-python>=4.4.0
numpy>=1.19.1
Pillow>=7.2.0
50 changes: 50 additions & 0 deletions simple-image-encryptor/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python
# python 3.8.5

from cv2 import imread, imwrite, bitwise_xor
from generator import genImage


def xor_cipher(image, key):
# simple xor cipher
return bitwise_xor(image, key)


def encrypt(image):
# generate image for the key
genImage()
key = imread("key.png")
# run xor cipher to encrypt image with the key
encrypted = xor_cipher(image, key)
# write the image to a file
imwrite('message_enc.png', encrypted)


def decrypt(image):
# read the key
key = imread("key.png")
# run xor cipher to decrypt image with the key
decrypted = xor_cipher(image, key)
# write the image to a file
imwrite('message.png', decrypted)


def main():
# read the message
msg_path = input(">>> Path to your image: ")
message = imread(msg_path)

# select mode
mode = input(">>> Enter mode (enc: encrypt, dec: decrypt): ")
# Conditional to check if user wants to
# encrypt or decrypt the image
if (mode == "enc"):
encrypt(message)
elif (mode == "dec"):
decrypt(message)


if __name__ == '__main__':
import sys
status = main()
sys.exit(status)