Skip to content

Commit bee1aec

Browse files
Merge branch 'x4nth055:master' into master
2 parents 7138991 + cf194de commit bee1aec

File tree

648 files changed

+108754
-3221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

648 files changed

+108754
-3221
lines changed

README.md

+88-3
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [Bluetooth Device Scanning in Python](https://thepythoncode.com/article/build-a-bluetooth-scanner-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Import bluetooth from the PyBluez module.
2+
import bluetooth
3+
4+
def scan_bluetooth_devices():
5+
try:
6+
# Discover Bluetooth devices with names and classes.
7+
discovered_devices = bluetooth.discover_devices(lookup_names=True, lookup_class=True)
8+
9+
# Display information about the scanning process.
10+
print('[!] Scanning for active devices...')
11+
print(f"[!] Found {len(discovered_devices)} Devices\n")
12+
13+
# Iterate through discovered devices and print their details.
14+
for addr, name, device_class in discovered_devices:
15+
print(f'[+] Name: {name}')
16+
print(f'[+] Address: {addr}')
17+
print(f'[+] Device Class: {device_class}\n')
18+
19+
except Exception as e:
20+
# Handle and display any exceptions that occur during device discovery.
21+
print(f"[ERROR] An error occurred: {e}")
22+
23+
24+
# Call the Bluetooth device scanning function when the script is run
25+
scan_bluetooth_devices()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pybluez2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Create a Custom Wordlist in Python](https://thepythoncode.com/article/make-a-wordlist-generator-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Import the argparse module for handling command line arguments.
2+
# Import the itertools module for generating combinations.
3+
import argparse, itertools
4+
5+
6+
# Define a function to generate a wordlist based on given parameters.
7+
def generate_wordlist(characters, min_length, max_length, output_file):
8+
# Open the output file in write mode.
9+
with open(output_file, 'w') as file:
10+
# Iterate over the range of word lengths from min_length to max_length.
11+
for length in range(min_length, max_length + 1):
12+
# Generate all possible combinations of characters with the given length.
13+
for combination in itertools.product(characters, repeat=length):
14+
# Join the characters to form a word and write it to the file
15+
word = ''.join(combination)
16+
file.write(word + '\n')
17+
18+
19+
# Create an ArgumentParser object for handling command line arguments.
20+
parser = argparse.ArgumentParser(description="Generate a custom wordlist similar to crunch.")
21+
22+
# Define command line arguments.
23+
parser.add_argument("-c", "--characters", type=str, default="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
24+
help="Set of characters to include in the wordlist")
25+
parser.add_argument("-min", "--min_length", type=int, default=4, help="Minimum length of the words")
26+
parser.add_argument("-max", "--max_length", type=int, default=6, help="Maximum length of the words")
27+
parser.add_argument("-o", "--output_file", type=str, default="custom_wordlist.txt", help="Output file name")
28+
29+
# Parse the command line arguments.
30+
args = parser.parse_args()
31+
32+
# Call the generate_wordlist function with the provided arguments.
33+
generate_wordlist(args.characters, args.min_length, args.max_length, args.output_file)
34+
35+
# Print a message indicating the wordlist has been generated and saved.
36+
print(f"[+] Wordlist generated and saved to {args.output_file}")
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# [How to Implement the Caesar Cipher in Python](https://thepythoncode.com/article/implement-caesar-cipher-in-python)
2+
# [How to Crack the Caesar Cipher in Python](https://thepythoncode.com/article/how-to-crack-caesar-cipher-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys # The sys module for system-related operations.
2+
from colorama import Fore, init # Import the colorama for colored text
3+
4+
init() # Initialize the colorama library for colored text.
5+
6+
7+
def implement_caesar_cipher(message, key, decrypt=False):
8+
# Initialize an empty string to store the result.
9+
result = ""
10+
# Iterate through each character in the user's input message.
11+
for character in message:
12+
# Check if the character is an alphabet letter.
13+
if character.isalpha():
14+
# Determine the shift amount based. i.e the amount of times to be shifted e.g 2,3,4....
15+
shift = key if not decrypt else -key
16+
# Check if the character is a lowercase letter.
17+
if character.islower():
18+
# Apply Caesar cipher transformation for lowercase letters.
19+
result += chr(((ord(character) - ord('a') + shift) % 26) + ord('a'))
20+
else:
21+
# Apply Caesar cipher transformation for uppercase letters.
22+
result += chr(((ord(character) - ord('A') + shift) % 26) + ord('A'))
23+
else:
24+
# Preserve non-alphabet characters as they are.
25+
result += character
26+
return result # Return the encrypted or decrypted result.
27+
28+
29+
# Prompt the user to enter the text to be encrypted
30+
text_to_encrypt = input(f"{Fore.GREEN}[?] Please Enter your text/message: ")
31+
# Prompt the user to specify the shift length (the key).
32+
key = int(input(f"{Fore.GREEN}[?] Please specify the shift length: "))
33+
34+
35+
# Check if the specified key is within a valid range (0 to 25).
36+
if key > 25 or key < 0:
37+
# Display an error message if the key is out of range.
38+
print(f"{Fore.RED}[!] Your shift length should be between 0 and 25 ")
39+
sys.exit() # Exit the program if the key is invalid.
40+
41+
# Encrypt the user's input using the specified key.
42+
encrypted_text = implement_caesar_cipher(text_to_encrypt, key)
43+
44+
# Display the encrypted text.
45+
print(f"{Fore.GREEN}[+] {text_to_encrypt} {Fore.MAGENTA}has been encrypted as {Fore.RED}{encrypted_text}")
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Import colorama for colorful text.
2+
from colorama import Fore, init
3+
4+
init()
5+
6+
7+
# Define a function for Caesar cipher encryption.
8+
def implement_caesar_cipher(text, key, decrypt=False):
9+
# Initialize an empty string to store the result.
10+
result = ""
11+
12+
# Iterate through each character in the input text.
13+
for char in text:
14+
# Check if the character is alphabetical.
15+
if char.isalpha():
16+
# Determine the shift value using the provided key (or its negation for decryption).
17+
shift = key if not decrypt else -key
18+
19+
# Check if the character is lowercase
20+
if char.islower():
21+
# Apply the Caesar cipher encryption/decryption formula for lowercase letters.
22+
result += chr(((ord(char) - ord('a') + shift) % 26) + ord('a'))
23+
else:
24+
# Apply the Caesar cipher encryption/decryption formula for uppercase letters.
25+
result += chr(((ord(char) - ord('A') + shift) % 26) + ord('A'))
26+
else:
27+
# If the character is not alphabetical, keep it as is e.g. numbers, punctuation
28+
result += char
29+
30+
# Return the result, which is the encrypted or decrypted text
31+
return result
32+
33+
34+
# Define a function for cracking the Caesar cipher.
35+
def crack_caesar_cipher(ciphertext):
36+
# Iterate through all possible keys (0 to 25) as there 26 alphabets.
37+
for key in range(26):
38+
# Call the caesar_cipher function with the current key to decrypt the text.
39+
decrypted_text = implement_caesar_cipher(ciphertext, key, decrypt=True)
40+
41+
# Print the result, showing the decrypted text for each key
42+
print(f"{Fore.RED}Key {key}: {decrypted_text}")
43+
44+
45+
# Initiate a continuous loop so the program keeps running.
46+
while True:
47+
# Accept user input.
48+
encrypted_text = input(f"{Fore.GREEN}[?] Please Enter the text/message to decrypt: ")
49+
# Check if user does not specify anything.
50+
if not encrypted_text:
51+
print(f"{Fore.RED}[-] Please specify the text to decrypt.")
52+
else:
53+
crack_caesar_cipher(encrypted_text)
54+
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
colorama
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Crack the Affine Cipher in Python](https://thepythoncode.com/article/how-to-crack-the-affine-cipher-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Import the needed libraries.
2+
import string
3+
from colorama import Fore, init
4+
5+
# Initialise colorama.
6+
init()
7+
8+
9+
# Function to get Euclidean Algorithm.
10+
def extended_gcd(a, b):
11+
"""
12+
Extended Euclidean Algorithm to find the greatest common divisor
13+
and coefficients x, y such that ax + by = gcd(a, b).
14+
"""
15+
if a == 0:
16+
return (b, 0, 1)
17+
else:
18+
g, x, y = extended_gcd(b % a, a)
19+
return (g, y - (b // a) * x, x)
20+
21+
22+
# Function to get the modular Inverse
23+
def modular_inverse(a, m):
24+
"""
25+
Compute the modular multiplicative inverse of a modulo m.
26+
Raises an exception if the modular inverse does not exist.
27+
"""
28+
g, x, y = extended_gcd(a, m)
29+
if g != 1:
30+
raise Exception('Modular inverse does not exist')
31+
else:
32+
return x % m
33+
34+
35+
# Function to decrypt our message.
36+
def affine_decrypt(ciphertext, a, b):
37+
"""
38+
Decrypt a message encrypted with the Affine Cipher using
39+
the given key components a and b.
40+
"""
41+
alphabet = string.ascii_uppercase
42+
m = len(alphabet)
43+
plaintext = ''
44+
45+
# Compute the modular multiplicative inverse of a.
46+
a_inv = modular_inverse(a, m)
47+
48+
# Iterate through each character in the ciphertext.
49+
for char in ciphertext:
50+
# Check if the character is in the alphabet
51+
if char in alphabet:
52+
# If it's an alphabet letter, decrypt it.
53+
# Find the index of the character in the alphabet.
54+
c = alphabet.index(char)
55+
# Apply the decryption formula: a_inv * (c - b) mod m.
56+
p = (a_inv * (c - b)) % m
57+
# Append the decrypted character to the plaintext.
58+
plaintext += alphabet[p]
59+
else:
60+
# If the character is not in the alphabet, keep it unchanged.
61+
plaintext += char
62+
63+
# Return the decrypted plaintext.
64+
return plaintext
65+
66+
67+
# Function to peform brute force attack.
68+
def affine_brute_force(ciphertext):
69+
"""
70+
Brute-force attack to find possible keys for an Affine Cipher
71+
and print potential decryptions for manual inspection.
72+
"""
73+
alphabet = string.ascii_uppercase
74+
m = len(alphabet)
75+
76+
# Iterate through possible values for a.
77+
for a in range(1, m):
78+
# Ensure a and m are coprime.
79+
if extended_gcd(a, m)[0] == 1:
80+
# Iterate through possible values for b.
81+
for b in range(0, m):
82+
# Decrypt using the current key.
83+
decrypted_text = affine_decrypt(ciphertext, a, b)
84+
85+
# Print potential decryption for manual inspection.
86+
print(f"Key (a={a}, b={b}): {decrypted_text}")
87+
88+
89+
ciphertext = input(f"{Fore.GREEN}[?] Enter Message to decrypt: ")
90+
91+
# Perform a brute-force attack to find potential decrypted message.
92+
affine_brute_force(ciphertext)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
colorama
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Perform DNS Enumeration in Python](https://www.thepythoncode.com/article/dns-enumeration-with-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import dns.resolver
2+
3+
# Set the target domain and record type
4+
target_domain = "thepythoncode.com"
5+
record_types = ["A", "AAAA", "CNAME", "MX", "NS", "SOA", "TXT"]
6+
# Create a DNS resolver
7+
resolver = dns.resolver.Resolver()
8+
for record_type in record_types:
9+
# Perform DNS lookup for the specified domain and record type
10+
try:
11+
answers = resolver.resolve(target_domain, record_type)
12+
except dns.resolver.NoAnswer:
13+
continue
14+
# Print the answers
15+
print(f"{record_type} records for {target_domain}:")
16+
for rdata in answers:
17+
print(f" {rdata}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dnspython
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Generate Fake User Data in Python](https://thepythoncode.com/article/generate-fake-user-data-in-python)

0 commit comments

Comments
 (0)