Package: drcrypt
DrCrypt - Python Encryption LibraryDrCrypt is a Python encryption library that provides various cryptographic functions for your projects. It aims to simplify encryption tasks and provide a user-friendly interface for common encryption algorithms.InstallationYou can installDrCryptusing pip:pipinstalldrcryptFeaturesEasy-to-use API for common encryption tasks.Supports various encryption algorithms, including MD5, SHA-256, SHA-3, and more.Provides functions for generating random strings and hashes.Well-documented and user-friendly interface.UsageXOR EncryptionHere's a quick example of how to useDrCryptto perform XOR encryption:fromdrcrypt.cryptimportXORtext="Hello, World"xor=XOR("MyPassword","utf-8")en=xor.encrypt(text)print("Text:",text,end="\n\n")print("Encrypt:",en)print("Decrypt:",xor.decrypt(en))In the provided code snippet, theXORclass from thedrcrypt.cryptmodule is imported. The example demonstrates how to use the XOR encryption feature ofDrCrypt. It encrypts the given text using the XOR cipher and a provided password. The encrypted text is then printed, followed by decrypting it using the same password and printing the decrypted result.AES Encryption and DecryptionHere's a simple example of how to useDrCryptto perform AES encryption and decryption:fromdrcrypt.cryptimportencrypt_aes,decrypt_aeskey="MyTestPassword!!".encode("utf-8")text="Hello, world"en=encrypt_aes(text,key)print("Text:",text,end="\n\n")print("Encrypted:",en.decode("utf-8"))print("Decrypted:",decrypt_aes(en,key).decode("utf-8"))In the provided code snippet, theencrypt_aesanddecrypt_aesfunctions from thedrcrypt.cryptmodule are imported. This example demonstrates how to useDrCryptto encrypt and decrypt data using the Advanced Encryption Standard (AES) algorithm. It encrypts the given text using the provided key, prints the original text, the encrypted result, and then decrypts the encrypted text using the same key and prints the decrypted result.HashingHere's a simple example of how to useDrCryptto generate an SHA-1 hash:fromdrcrypt.hashimportSHA1data="Hello, SHA-1!"sha1_hash=SHA1()sha1_hash.update(data.encode("utf-8"))sha1_hash.finalize()hashed=sha1_hash.hexdigest()print("Data:",data)print("SHA-1 Hash:",hashed)In the provided code snippet, theSHA1class from thedrcrypt.hashmodule is imported. This example demonstrates how to useDrCryptto compute the SHA-1 hash of a given string (data). It initializes the SHA-1 hash object, updates it with the data, finalizes the hash computation, and then prints the original data and its corresponding SHA-1 hash.Here's a simple example of how to useDrCryptto generate an SHA-256 hash:fromdrcrypt.hashimportSHA256data="Hello, SHA-256!"sha256_hash=SHA256()sha256_hash.update(data.encode("utf-8"))sha256_hash.finalize()hashed=sha256_hash.hexdigest()print("Data:",data)print("SHA-256 Hash:",hashed)In the provided code snippet, theSHA256class from thedrcrypt.hashmodule is imported. This example demonstrates how to useDrCryptto compute the SHA-256 hash of a given string (data). It initializes the SHA-256 hash object, updates it with the data, finalizes the hash computation, and then prints the original data and its corresponding SHA-256 hash.Here's a simple example of how to useDrCryptto generate an MD5 hash:fromdrcrypt.hashimportMD5data="Hello, MD5!"md5_hash=MD5()md5_hash.update(data.encode("utf-8"))md5_hash.finalize()hashed=md5_hash.hexdigest()print("Data:",data)print("MD5 Hash:",hashed)In the provided code snippet, theMD5class from thedrcrypt.hashmodule is imported. This example demonstrates how to useDrCryptto compute the MD5 hash of a given string (data). It initializes the MD5 hash object, updates it with the data, finalizes the hash computation, and then prints the original data and its corresponding MD5 hash.Comparing HashesHere's an example of how to useDrCryptto compute and compare MD5 hashes:fromdrcrypt.hashimportMD5fromdrcryptimportcompare_hashdata="Hello, MD5!"md5_hash=MD5()md5_hash.update(data.encode("utf-8"))md5_hash.finalize()hashed=md5_hash.hexdigest()result=compare_hash(MD5(),data,hashed)ifresult:print("Hashes match! The data matches the target hash.")else:print("Hashes do not match. The data does not match the target hash.")In the provided code snippet, theMD5class from thedrcrypt.cryptmodule is used to compute an MD5 hash for a given string (data). Thecompare_hashfunction is then used to compare the computed hash with the target hash (hashed). The example demonstrates how to verify whether the data matches the target hash and prints a corresponding message.Secure Password Hashing and VerificationHere's an example of how to use theBcryptclass fromDrCryptto perform secure password hashing and verification:fromdrcrypt.hashimportBcrypt# Create an instance of Bcryptbcrypt_hasher=Bcrypt()# Hash a password and generate a saltpassword="mysecretpassword"salt=bcrypt_hasher.generate_salt()hashed_password=bcrypt_hasher.bcrypt_hash(password,salt)# Verify an entered passwordinput_password="mysecretpassword"ifbcrypt_hasher.verify_password(input_password,hashed_password):print("Password Matched!")else:print("Password Does Not Match!")In the provided code snippet, the `Bcryptclass from thedrcrypt.hashmodule is used. This example demonstrates how to useDrCryptto securely hash and verify passwords using the bcrypt algorithm. It creates an instance of theBcrypt` class, hashes a password with a generated salt, and then verifies an entered password against the hashed password.Generating Random Numbers and StringsHere's an example of how to use theRandomclass fromDrCryptto generate random numbers and strings:fromdrcryptimportRandom# Create an instance of Randomr=Random()# Generate a random integer between 1 and 10random_int=r.randint(1,10)print("Random Integer:",random_int)# Generate a random string with characters "AaBbCcDd1234567890" and length 10random_str=r.randstr(10,"AaBbCcDd1234567890")print("Random String:",random_str)In the provided code snippet, theRandomclass from thedrcrypt.randommodule is used. This example demonstrates how to useDrCryptto generate random numbers and strings. It creates an instance of theRandomclass and then generates a random integer within the specified range and a random string with the specified characters and length.DocumentationFor detailed documentation and examples, please refer to theofficial documentation.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details.