Skip to content

Commit 7a7c1ca

Browse files
authored
Merge branch 'avinashkranjan:master' into master
2 parents af26c5e + 2717a2c commit 7a7c1ca

File tree

12 files changed

+1184
-74
lines changed

12 files changed

+1184
-74
lines changed

Discord-Bot/main.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,52 @@
11
import random
2-
32
import discord
43
from discord.ext import commands
54

6-
# your token here, inside the ""
5+
# Your token here, inside the ""
76
TOKEN = ""
8-
# channel to send welcome messages to
7+
# Channel to send welcome messages to
98
WELCOME_CHANNEL = "welcome"
10-
# all the nicknames for the random_nickname command
9+
# All the nicknames for the random_nickname command
1110
NICKS = ["example1", "example2", "example3"]
1211

13-
# you can change the prefix here
12+
# You can change the prefix here
1413
bot = commands.Bot(command_prefix="!")
1514

1615

1716
@bot.event
1817
async def on_ready():
19-
print("bot started")
18+
print("Bot started")
2019

2120

2221
@bot.event
2322
async def on_member_join(member):
24-
welcome_channel = discord.utils.get(member.guild.channels,
25-
name=WELCOME_CHANNEL)
26-
# feel free to change this message!
27-
await welcome_channel.send(
28-
f"welcome {member.mention}, please read our rules and have a great time!"
29-
)
23+
welcome_channel = discord.utils.get(member.guild.channels, name=WELCOME_CHANNEL)
24+
# Feel free to change this message!
25+
await welcome_channel.send(f"Welcome {member.mention}! Please read our rules and have a great time!")
3026

3127

3228
@commands.has_permissions(ban_members=True)
3329
@bot.command()
3430
async def ban(ctx, user: discord.Member):
3531
"""Ban the given user"""
3632
await ctx.guild.ban(user, delete_message_days=0)
37-
await ctx.send(f"banned {user}")
33+
await ctx.send(f"Banned {user}")
3834

3935

4036
@commands.has_permissions(ban_members=True)
4137
@bot.command()
4238
async def unban(ctx, user: discord.User):
43-
"Unban the given user"
39+
"""Unban the given user"""
4440
await ctx.guild.unban(user)
45-
await ctx.send(f"unbanned {user}")
41+
await ctx.send(f"Unbanned {user}")
4642

4743

4844
@commands.has_permissions(kick_members=True)
4945
@bot.command()
5046
async def kick(ctx, user: discord.User):
51-
"Kick the given user"
47+
"""Kick the given user"""
5248
await ctx.guild.kick(user)
53-
await ctx.send(f"kicked {user}")
49+
await ctx.send(f"Kicked {user}")
5450

5551

5652
@bot.command(aliases=["rnick"])
@@ -64,9 +60,9 @@ async def random_nick(ctx):
6460
@commands.has_permissions(manage_nicknames=True)
6561
@bot.command(aliases=["change_name"])
6662
async def change_nick(ctx, user: discord.Member, *, new_nick):
67-
"""Change somebody elses nickname."""
63+
"""Change somebody else's nickname"""
6864
await user.edit(nick=new_nick)
69-
await ctx.send(f"Changed the nick of {user.mention} to `{new_nick}`")
65+
await ctx.send(f"Changed the nickname of {user.mention} to `{new_nick}`")
7066

7167

7268
if __name__ == "__main__":

File-Encrypter/README.md

2.74 KB

File Encrypter

This is a command-line interface (CLI) tool that provides secure file encryption and decryption functionalities. The tool allows users to encrypt sensitive files using a strong encryption algorithm, making the contents unreadable to unauthorized individuals. It also enables users to decrypt encrypted files, restoring them to their original state.

Install Dependencies

  • Step 1 : Clone the Repository
  • Step 2 : Change directory to File-Encrypter
  cd Amazing-Python-Scripts/File-Encrypter
  • Step 3: run the command
 pip install -r requirements.txt  

Usage

  • Create a file with the content you want to encrypt in the same directory as the script, the run -
  python script.py <file_name> encrypt
  • Congratulations ! The file is encrypted. You would notice that your original file is gone and replaced with a .encrypted file of the same name. To decrypt it run -
  python script.py <file_name.encrypted> decrypt
  • For more info, run this -
  python script.py --help

secret.key

This is a crucial file generated automatically when you first encrypt your file. It contained the main Encryption Key. It needs to be present in the same folder too. If you're really planning to hide some important data, better move this file somewhere else. But dont lose it.

File-Encrypter/requirements.txt

50 Bytes
Binary file not shown.

File-Encrypter/script.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from cryptography.fernet import Fernet
2+
import os
3+
import sys
4+
import argparse
5+
6+
def generate_key():
7+
return Fernet.generate_key()
8+
9+
def save_key(key, file_path):
10+
# save encryption key to a file
11+
with open(file_path,'wb') as f:
12+
f.write(key)
13+
14+
def load_key(file_path):
15+
with open(file_path,'rb') as f:
16+
return f.read()
17+
18+
def encrypt_file(key,file_path):
19+
f=Fernet(key)
20+
with open(file_path,'rb') as f_input:
21+
data = f_input.read()
22+
encrypted_data = f.encrypt(data)
23+
with open(file_path.split(".")[0]+'.encrypted','wb') as f_output:
24+
f_output.write(encrypted_data)
25+
os.remove(file_path)
26+
27+
def decrypt_file(key, file_path):
28+
f=Fernet(key)
29+
with open (file_path,'rb') as f_enc:
30+
data = f_enc.read()
31+
dec_data = f.decrypt(data)
32+
with open(file_path.split(".")[0]+".txt",'wb') as f_dec:
33+
f_dec.write(dec_data)
34+
os.remove(file_path)
35+
36+
if __name__ == "__main__":
37+
parser = argparse.ArgumentParser(description = "[*]Encrypt youre files and password protect them")
38+
parser.add_argument('file_path', help="Add the name of the file to be encrypted")
39+
parser.add_argument('mode',choices=['encrypt','decrypt'],help="Choose either encrypt or decrypt")
40+
args = parser.parse_args()
41+
42+
if args.mode == "encrypt":
43+
key = generate_key()
44+
save_key(key,"secret.key")
45+
encrypt_file(key,args.file_path)
46+
print("Encrypted")
47+
else:
48+
key = load_key("secret.key")
49+
50+
decrypt_file(key, args.file_path )
51+
print("Decrypted")

Photo To Ascii/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

2-
<h1 align="center"> Photo to Ascii</h1>
3-
Convert your photo to ascii with it
2+
<h1 align="center">Photo to Ascii</h1>
3+
Convert your image to ASCII art using this simple python script!
44

5-
---------------------------------------------------------------------
5+
---
66

77
## Modules Used
88
- pillow
99

10-
1110
## How it works
12-
- First you have to enter the correct path where your photp is located.
13-
- Then it will resize your photo and grayify it
14-
- Then it will convert your photo to ascii
15-
- Then you could find your photo in {image_name}(ASCII).txt file where image_name is the name of your photo
11+
- First you have to enter the correct path where your image is located.
12+
- Then it will resize your image and grayify it.
13+
- Then it will convert your image to ascii.
14+
- Then it will save the ascii art to the file {imageFile-name}_{imageFile-extension}_ASCII.txt, located in the same folder as your image.
1615

17-
#### By [Avishake Maji](https://github.com/Avishake007)
16+
#### Created By [Avishake Maji](https://github.com/Avishake007)
17+
#### Improved By [Aryan Rai](https://github.com/aryanrai2001)

Photo To Ascii/photo_to_ascii.py

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,49 @@
11
from PIL import Image
22

3-
# ascii characters used to build the output text
3+
# ASCII characters used to build the output text
44
CHARS = [".", ".", ".", "1", "1", "1", "1", "1", "0", "0", "0"]
5-
# convert each pixel to grayscale
6-
7-
8-
def grayify(image):
9-
grayscale_image = image.convert("L")
10-
return(grayscale_image)
11-
12-
# convert pixels to a string of ascii characters
13-
145

6+
# Convert pixels to a string of ASCII characters
157
def pixels_to_ascii(image):
16-
pixels = image.getdata()
17-
characters = "".join([CHARS[pixel//23] for pixel in pixels])
8+
pixels = image.convert("L").getdata()
9+
characters = " ".join([CHARS[int((pixel/256)*len(CHARS))] for pixel in pixels])
1810
return(characters)
1911

20-
2112
def photoascii():
22-
23-
# attempt to open image from user-input
13+
# Attempt to open image file from user-input
2414
path = input("Enter a valid pathname to an image:\n")
2515
try:
2616
image = Image.open(path)
2717
except Exception:
2818
print("Invalid path")
2919
return
30-
# Fetching the name of the image
31-
image_name = ""
32-
flag = 0
33-
for i in path[::-1]:
34-
if i == "/":
35-
break
36-
if flag == 1:
37-
image_name = i+image_name
38-
if i == '.':
39-
flag = 1
40-
41-
# Resizing of image
20+
21+
# Fetch the name of the image file
22+
dot_index = path.rfind('.')
23+
slash_index = path.rfind('\\')
24+
if slash_index == -1:
25+
slash_index = path.rfind('/')
26+
image_name = path[slash_index+1:dot_index] + "_" + path[dot_index+1:]
27+
28+
# Resize image
4229
new_width = 100
4330
width, height = image.size
4431
ratio = height/width
4532
new_height = int(new_width * ratio)
4633
resized_image = image.resize((new_width, new_height))
4734

48-
# convert image to ascii
49-
new_image_data = pixels_to_ascii(grayify(resized_image))
50-
35+
# Convert image to ASCII
36+
new_image_data = pixels_to_ascii(resized_image)
5137
pixel_count = len(new_image_data)
52-
ascii_image = "\n".join([new_image_data[index:(index+new_width)]
53-
for index in range(0, pixel_count, new_width)])
38+
scanline_width = new_width * 2;
39+
ascii_image = "\n".join([new_image_data[index:(index+scanline_width)]
40+
for index in range(0, pixel_count, scanline_width)])
5441

55-
# save result to "ascii_image.txt"
56-
with open("./Photo To Ascii/{}(ASCII).txt".format(image_name), "w") as f:
42+
# Save result to text file
43+
with open(path[:slash_index] + "/{}_ASCII.txt".format(image_name), "w") as f:
5744
f.write(ascii_image)
5845

5946

60-
# run program
47+
# Run Program
6148
if __name__ == '__main__':
6249
photoascii()

Plagiarism-Checker/README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1-
<h3 align="center">Plagiarism Checker</h3>
1+
<h1 align="center">Plagiarism Checker</h1>
22

3-
## How it works <br><br>
4-
- In order to compute the simlilarity between two text documents, the textual raw data is transformed into vectors.
5-
- Then it is transformed into arrays of numbers and then from that by using a basic knowledge vector to compute the the similarity between them.
3+
## Introduction <br>
4+
- Plagiarism checking/detection is the identification of similarities between texts and establishing if one text is derived from another, and it may be used to spot situations of academic dishonesty or unauthorised copying.
5+
- This code analyses the textual data and looks for possible instances of plagiarism using TF-IDF (Term Frequency-Inverse Document Frequency) vectorization and cosine similarity.
66

7-
## Dependencies<br>
8-
- Install scikit-learn by:
7+
## Prerequisites <br>
8+
- Install scikit-learn by: '**$ pip install scikit-learn**'
99

10-
$ pip install scikit-learn
10+
## How it works <br>
11+
1. There are four text documents in the repository.
12+
2. The paths to text files that are located in the same directory as the code file are loaded at the beginning of the code. It recognises and records the paths of all files with the **.txt** extension in the **student_files** list.
13+
3. Next, the code reads the contents of each text file and stores them in the **student_notes** list.
14+
4. **The TfidfVectorizer** class from scikit-learn is used by the **vectorize** function to perform TF-IDF vectorization on a list of text documents. The relative relevance of each term in a document in relation to the corpus of texts is captured by the TF-IDF, a numerical representation of textual data. The function returns arrays of numbers that represent the documents' TF-IDF vectors.
15+
5. The **similarity** function computes the cosine similarity between two document vectors. Cosine similarity measures the cosine of the angle between two vectors and is commonly used to compare the similarity of documents represented as vectors. The function returns the similarity score between the two input vectors.
16+
6. The code with the help of the **vectorize** function vectorizes the textual data, converting it to numerical arrays using TF-IDF representation.
17+
7. The vectorized data is then paired with their corresponding student files and stored in the **s_vectors** list.
18+
8. The **check_plagiarism** function compares the vectorized documents of each pair of students using cosine similarity. It iterates through each student's vector and compares it with the vectors of all other students. For each pair of students, it computes the similarity score using the **similarity** function and stores the student pair and their similarity score in the **plagiarism_results** set.
19+
9. And at last the code loops through the **plagiarism_results** set and prints the student pairings along with their similarity ratings.
1120

12-
## Running the app <br>
13-
- There are four text documents in the repository.
14-
- Basically the code will compare all the .txt files and check for any similarity.
21+
- $ python plagiarism.py
1522

16-
$ python plagiarism.py
23+
## Notes <br>
24+
- Please make sure the text files are readable and contain textual processable data.
25+
- The text files must be in the same directory as the code file.
26+
- If not need to provide the appropriate path in the **student_files** section of the code.
1727

1828
## Screenshots
1929
<img src="https://raw.githubusercontent.com/Anupreetadas/plagiarism_checker/main/assets/Capture1.PNG" width="100%" height="100%" align="left" >

0 commit comments

Comments
 (0)